/*
package com.lyf.scm.plan.domain.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableList;
import com.lyf.scm.common.constants.CommonConstants;
import com.lyf.scm.common.enums.*;
import com.lyf.scm.common.model.ExcelExportDataDTO;
import com.lyf.scm.common.util.AdvancedSearchUtil;
import com.lyf.scm.common.util.ExcelExportUtil;
import com.lyf.scm.common.util.date.MyDateUtil;
import com.lyf.scm.common.util.style.GeneralCellWriteHandler;
import com.lyf.scm.plan.api.dto.*;
import com.lyf.scm.plan.api.dto.excel.SalesWriteDTO;
import com.lyf.scm.plan.domain.convertor.SalesPlanOtherConvertor;
import com.lyf.scm.plan.domain.remote.basedata.dto.AreaDTO;
import com.lyf.scm.plan.domain.remote.basedata.dto.StoreDTO;
import com.lyf.scm.plan.domain.remote.basedata.facade.BaseDataFacade;
import com.lyf.scm.plan.domain.remote.category.dto.StorePackageSkuDTO;
import com.lyf.scm.plan.domain.remote.category.facade.CategoryFacade;
import com.lyf.scm.plan.domain.remote.item.dto.*;
import com.lyf.scm.plan.domain.remote.item.facade.ItemCoreFacade;
import com.lyf.scm.plan.domain.remote.transaction.dto.NewPlanDTO;
import com.lyf.scm.plan.domain.remote.transaction.facade.TransactionFacade;
import com.lyf.scm.plan.domain.repository.*;
import com.lyf.scm.plan.domain.service.SalesPlanOtherEsService;
import com.lyf.scm.plan.domain.service.SalesPlanOtherService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import com.rome.arch.util.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;

*/
/**
 * description:
 * 其他渠道计划serviceImpl
 *
 * @author: huangtao
 * @data: 2020/7/31
 *//*

@Slf4j
@Service
public class SalesPlanOtherServiceImpl implements SalesPlanOtherService {
    @Resource
    private SalesPlanOtherRespository salesPlanOtherRespository;

    @Resource
    private ItemCoreFacade itemCoreFacade;

    @Resource
    private SalesPlanOtherConvertor salesPlanOtherConvertor;

    @Resource
    private BaseDataFacade baseDataFacade;

    @Resource
    private CategoryFacade categoryFacade;

    @Resource
    private RolePermissionsRepository rolePermissionsRepository;

    @Resource
    private RoleAuthorityAreaRepository roleAuthorityAreaRepository;

    @Resource
    private TransactionFacade transactionFacade;

    @Resource
    private OperationLogRecordRepository operationLogRecordRepository;

    @Resource
    private SalesPlanOtherEsService salesPlanOtherEsService;

    @Resource
    private SalesPlanPermissionsRespository salesPlanPermissionsRespository;

    */
/**
     * 按条件查询其他渠道计划（周）
     *
     * @param salesPlanOther
     * @return
     *//*

    @Override
    public PageInfo<SalesPlanOtherInfoDTO> listWeekBySelective(SalesPlanOtherDTO salesPlanOther) {
        //根据日期获取间隔日期集合,没有结束时间，默认14周
        List<Map<String, Date>> weekDates = MyDateUtil.getWeekDates(salesPlanOther.getStartTime(), CommonConstants.WEEK_SIZE);
        salesPlanOther.setWeekDateList(weekDates);
        salesPlanOther.setEndTime(MyDateUtil.getLastDate(null, weekDates));
        PageInfo<SalesPlanOtherInfoDTO> dtoPageInfo = new PageInfo<>();
        Long userId = salesPlanOther.getCreator();
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = getRoleAreaList(userId);
        //一个用户只有一个级别（1:渠道、渠道下级（1级导入，确认），2：全渠道（2级确认））
        Integer level = roleAreaList.get(0).getPermissionsLevel();
        List<String> channels = new ArrayList<>();
        roleAreaList.forEach(item -> {
            String channel = item.getPermissionsCode();
            channels.add(channel);
        });
        //高级搜索不选择渠道，查询用户对应渠道
        if (CollectionUtils.isEmpty(salesPlanOther.getChannelCodeList())) {
            salesPlanOther.setChannelCodeList(channels);
        }
        //高级搜索对应计划类型
        //List<SalesPlanOtherTypeDTO> typeList = new ArrayList<>();
        //导入对应计划类型
        //List<SalesPlanOtherTypeDTO> typeImpList = new ArrayList<>();
        */
/*for (SalesOtherTypeEnum value : SalesOtherTypeEnum.values()) {
            SalesPlanOtherTypeDTO dto = new SalesPlanOtherTypeDTO();
            //查看一个渠道对应的计划类型是导入人或者渠道负责人
            if (channels.size() == 1) {
                String item = channels.get(0);
                if (item.equals(ChannelTypeEnum.DIRECTLY_OPERATE.getCode())) {
                    //直营包含的计划类型
                    if ("1".equals(value.getType()) || "6".equals(value.getType()) || "7".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeList.add(dto);
                    }
                } else if (item.equals(ChannelTypeEnum.JOIN_IN.getCode())) {
                    //加盟包含的计划类型
                    if ("2".equals(value.getType()) || "5".equals(value.getType()) || "11".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeList.add(dto);
                    }
                } else if (item.equals(ChannelTypeEnum.CLOUD_BUSINESS.getCode())) {
                    //云商包含的计划类型
                    if ("3".equals(value.getType()) || "8".equals(value.getType()) || "14".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeList.add(dto);
                    }
                } else if (item.equals(ChannelTypeEnum.APP.getCode())) {
                    //APP包含的计划类型
                    if ("4".equals(value.getType()) || "9".equals(value.getType()) || "12".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeList.add(dto);
                    }
                } else if (item.equals(ChannelTypeEnum.DEALER.getCode())) {
                    //经销中心包含的计划类型
                    if ("10".equals(value.getType()) || "13".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeList.add(dto);
                    }
                }
            } else {
                //查看全渠道所有计划类型的是导入人或者全渠道负责人
                dto.setType(value.getType());
                dto.setTypeName(value.getDesc());
                typeList.add(dto);
            }
        }*//*

        //导入只有一级权限有
        */
/*if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_ONE)) {
            for (SalesPlanTypeEnum value : SalesPlanTypeEnum.values()) {
                SalesPlanOtherTypeDTO dto = new SalesPlanOtherTypeDTO();
                //导入一个渠道
                if (channels.size() == 1) {
                    String item = channels.get(0);
                    if (item.equals(ChannelTypeEnum.JOIN_IN.getCode())) {
                        //加盟包含的计划类型
                        if ("11".equals(value.getType())) {
                            dto.setType(value.getType());
                            dto.setTypeName(value.getDesc());
                            typeImpList.add(dto);
                        }
                    } else if (item.equals(ChannelTypeEnum.CLOUD_BUSINESS.getCode())) {
                        //云商包含的计划类型
                        if ("14".equals(value.getType())) {
                            dto.setType(value.getType());
                            dto.setTypeName(value.getDesc());
                            typeImpList.add(dto);
                        }
                    } else if (item.equals(ChannelTypeEnum.APP.getCode())) {
                        //APP包含的计划类型
                        if ("12".equals(value.getType())) {
                            dto.setType(value.getType());
                            dto.setTypeName(value.getDesc());
                            typeImpList.add(dto);
                        }
                    } else if (item.equals(ChannelTypeEnum.DEALER.getCode())) {
                        //经销中心包含的计划类型
                        if ("13".equals(value.getType())) {
                            dto.setType(value.getType());
                            dto.setTypeName(value.getDesc());
                            typeImpList.add(dto);
                        }
                    }
                } else {
                    if ("15".equals(value.getType()) || "16".equals(value.getType())) {
                        dto.setType(value.getType());
                        dto.setTypeName(value.getDesc());
                        typeImpList.add(dto);
                    }
                }
            }
        }*//*

        //分页转换为查询的DTO
        */
/*List<SalesPlanOtherDTO> list = salesPlanOtherRespository.listWeekBySelectivePage(salesPlanOther).getList();
        if (CollectionUtils.isEmpty(list)) {
            return new PageInfo<>();
        }
        salesPlanOther = dealDataSelect(list,salesPlanOther);*//*

        //根据高级搜索条件查询分页的信息
        PageInfo<Map<String, String>> listPageInfo = salesPlanOtherRespository.listWeekBySelective(salesPlanOther);
        List<SalesPlanOtherInfoDTO> salesPlan = groupTarget(listPageInfo.getList(), level);
        if (CollectionUtils.isEmpty(salesPlan)) {
            return dtoPageInfo;
        }
        //转换单位(数据库存的基础单位，不用转换)
        if (!SkuUnitTypeEnum.BASIS_UNIT.getUnitType().equals(salesPlanOther.getUnitType())) {
            List<String> skuCodeList = salesPlan.stream().map(SalesPlanOtherInfoDTO::getSkuCode).distinct().collect(Collectors.toList());
            //处理单位
            List<SkuUnitDTO> skuUnitList = itemCoreFacade.getConversionRatio(skuCodeList, salesPlanOther.getUnitType());
            this.calculationProBySelect(salesPlan, skuUnitList);
        }
        dtoPageInfo.setList(salesPlan);
        dtoPageInfo.setTotal(listPageInfo.getTotal());
        //查询对应的指标
        */
/*if (ObjectUtil.isNotEmpty(list)) {
            List<SalesPlanOtherDTO> salesPlan = salesPlanOtherRespository.listSalesAndTarget(salesPlanOtherDO);
            if (!SkuUnitTypeEnum.BASIS_UNIT.getUnitType().equals(salesPlanOther.getUnitType())) {
                List<String> skuCodeList = salesPlan.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList());
                //处理单位
                List<SkuUnitDTO> skuUnitList = itemCoreFacade.getConversionRatio(skuCodeList, salesPlanOther.getUnitType());
                this.calculationPro(salesPlan, skuUnitList);
            }
            //设置分组依据的key值
            this.getGroupByKey(salesPlan, salesPlanOther);
            //将数据分组
            Map<String, List<SalesPlanOtherDTO>> collect = salesPlan.stream().collect(Collectors.groupingBy(SalesPlanOtherDTO::getCondition, Collectors.toList()));
            //处理分组后的数据
            dtoPageInfo.setList(this.getTargetList(collect, salesPlanOther, level, typeList, typeImpList));
            dtoPageInfo.setTotal(collect.values().size());
        } else {
            List<SalesPlanOtherInfoDTO> infos = new ArrayList<>();
            SalesPlanOtherInfoDTO info = new SalesPlanOtherInfoDTO();
            info.setLevel(level);
            info.setOtherTypeList(typeList);
            info.setOtherImpTypeList(typeImpList);
            infos.add(info);
            dtoPageInfo.setList(infos);
        }*//*

        return dtoPageInfo;
    }

    private List<SalesPlanPermissionsDTO> getRoleAreaList(Long userId) {
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = salesPlanPermissionsRespository.listByUserId(userId);
        if (CollectionUtils.isEmpty(roleAreaList)) {
            throw new RomeException(ResponseMsg.FAIL_2004.getCode(), ResponseMsg.FAIL_2004.getMsg());
        }
        //渠道不为空为其他渠道计划用户
        roleAreaList = roleAreaList.stream().filter(item -> PermissionCodeEnum.CHANNEL.getCode().equals(item.getPermissionsType())).collect(Collectors.toList());
        if (roleAreaList.size() == 0) {
            throw new RomeException(ResponseMsg.FAIL_2004.getCode(), ResponseMsg.FAIL_2004.getMsg());
        }
        return roleAreaList;
    }

    */
/**
     * 查询全渠道其他渠道计划(范围)
     *
     * @param salesPlanOther
     * @return
     *//*

    @Override
    public List<SalesPlanOtherInfoDTO> listAllByCycles(SalesPlanOtherDTO salesPlanOther) {
        //如果开始时间为空
        if (ObjectUtil.isEmpty(salesPlanOther.getStartTime())) {
            salesPlanOther.setStartTime(DateUtil.beginOfWeek(new Date()));
        } else {
            salesPlanOther.setStartTime(DateUtil.beginOfWeek(salesPlanOther.getStartTime()));
        }
        //如果结束时间为空
        if (ObjectUtil.isEmpty(salesPlanOther.getEndTime())) {
            salesPlanOther.setEndTime(DateUtil.beginOfWeek(DateUtil.offsetWeek(new Date(), CommonConstants.WEEK_TARGET_SIZE)));
        } else {
            salesPlanOther.setEndTime(DateUtil.endOfWeek(salesPlanOther.getEndTime()));
        }
        List<Map<String, Date>> weekDates = MyDateUtil.getWeekDates(salesPlanOther.getStartTime(), CommonConstants.WEEK_SIZE);
        salesPlanOther.setWeekDateList(weekDates);
        Long userId = salesPlanOther.getCreator();
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = getRoleAreaList(userId);
        //一个用户只有一个级别（1:渠道、渠道下级（1级导入，确认），2：全渠道（2级确认））
        Integer level = roleAreaList.get(0).getPermissionsLevel();
        List<String> channels = new ArrayList<>();
        roleAreaList.forEach(item -> {
            String channel = item.getPermissionsCode();
            channels.add(channel);
        });
        if (CollectionUtils.isEmpty(salesPlanOther.getChannelCodeList())) {
            salesPlanOther.setChannelCodeList(channels);
        }
        List<SalesPlanOtherDTO> resultList = salesPlanOtherRespository.listAllByCycles(salesPlanOther);
        if (!SkuUnitTypeEnum.BASIS_UNIT.getUnitType().equals(salesPlanOther.getUnitType())) {
            //获取不重复的skuCode集合
            List<String> skuCodeList = resultList.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList());
            //获取单位换算比例
            List<SkuUnitDTO> skuUnitList = itemCoreFacade.getConversionRatio(skuCodeList, salesPlanOther.getUnitType());
            //根据获取的换算比例计算指标数量
            this.calculationPro(resultList, skuUnitList);
        }
        //设置分组依据的key值
        this.getGroupByKey(resultList, salesPlanOther);
        //将数据分组
        Map<String, List<SalesPlanOtherDTO>> paramMap = resultList.stream().collect(Collectors.groupingBy(SalesPlanOtherDTO::getCondition, Collectors.toList()));
        // 汇总分组后的数据
        List<SalesPlanOtherInfoDTO> salesPlanDirectlyList = this.getTargetList(paramMap, salesPlanOther, level);
        return salesPlanDirectlyList;
    }


    */
/**
     * 获取当前用户其他渠道计划级别
     *
     * @param userId
     * @return
     *//*

    @Override
    public Integer getOtherPlanLevel(Long userId) {
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = getRoleAreaList(userId);
        //一个用户只有一个级别（1:渠道、渠道下级（1级导入，确认），2：全渠道（2级确认））
        Integer level = roleAreaList.get(0).getPermissionsLevel();
        return level;
    }

    */
/**
     * 导出所有查询数据
     *
     * @param salesPlanOtherDTO
     * @param type
     * @throws Exception
     *//*

    @Override
    public ExcelExportDataDTO export(SalesPlanOtherDTO salesPlanOtherDTO, Integer type) throws Exception {
        // 获取日期标题
        List<String> dateTitles = MyDateUtil.processCyclesDate(salesPlanOtherDTO.getWeekDateList(), "MM.dd");
        //增加合计
        dateTitles.add("合计");
        List<SalesPlanOtherDTO> salesPlanDTOList = new ArrayList<>();
        List<List<Object>> exportDataList = null;
        Long userId = salesPlanOtherDTO.getCreator();
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = getRoleAreaList(userId);
        //一个用户只有一个级别（1:渠道、渠道下级（1级导入，确认），2：全渠道（2级确认））
        Integer level = roleAreaList.get(0).getPermissionsLevel();
        List<String> channels = new ArrayList<>();
        roleAreaList.forEach(item -> {
            String channel = item.getPermissionsCode();
            channels.add(channel);
        });
        //高级搜索不选择渠道，查询用户对应渠道
        if (CollectionUtils.isEmpty(salesPlanOtherDTO.getChannelCodeList())) {
            salesPlanOtherDTO.setChannelCodeList(channels);
        }
        //指标名称集合
        List<String> allTargetsDesc = SalesPlanOtherEnum.getAllTargetsDesc(level);
        List<SalesPlanOtherInfoDTO> salesPlan = new ArrayList<>();
        //全部数据导出
        if (ExcelExportTypeEnum.SEARCHED_DATA_EXPORT.getType().equals(type)) {
            List<Map<String, String>> mapList = salesPlanOtherRespository.listWeekBySelectiveAll(salesPlanOtherDTO);
            salesPlan = groupTarget(mapList, level);
            //salesPlanDTOList = salesPlanOtherRespository.listAllByCondition(salesPlanOtherDTO);
        }
        //当前页数据导出
        if (ExcelExportTypeEnum.CURRENT_PAGE_EXPORT.getType().equals(type)) {
            PageInfo<Map<String, String>> mapList = salesPlanOtherRespository.listWeekBySelective(salesPlanOtherDTO);
            salesPlan = groupTarget(mapList.getList(), level);
            */
/*List<SalesPlanOtherDO> list = salesPlanOtherRespository.listWeekBySelective(salesPlanOtherDTO).getList();
            if (ObjectUtil.isNotEmpty(list)) {
                SalesPlanOtherDO salesPlanOtherDO = dealData(list, salesPlanOtherDTO);
                salesPlanDTOList = salesPlanOtherRespository.listSalesAndTarget(salesPlanOtherDO);
            }*//*

        }
        //导出选中的数据
        if (ExcelExportTypeEnum.CHECKED_BOX_EXPORT.getType().equals(type)) {
            PageInfo<Map<String, String>> mapList = salesPlanOtherRespository.listWeekBySelective(salesPlanOtherDTO);
            salesPlan = groupTarget(mapList.getList(), level);
        }
        if (CollectionUtils.isEmpty(salesPlan)) {
            throw new RomeException(ResponseMsg.FAIL_2005.getCode(), ResponseMsg.FAIL_2005.getMsg());
        }
        if (!SkuUnitTypeEnum.BASIS_UNIT.getUnitType().equals(salesPlanOtherDTO.getUnitType())) {
            List<String> skuCodeList = salesPlan.stream().map(SalesPlanOtherInfoDTO::getSkuCode).distinct().collect(Collectors.toList());
            //处理单位
            List<SkuUnitDTO> skuUnitList = itemCoreFacade.getConversionRatio(skuCodeList, salesPlanOtherDTO.getUnitType());
            this.calculationProBySelect(salesPlan, skuUnitList);
        }

        //设置分组依据的key值
        //this.getGroupByKey(salesPlanDTOList, salesPlanOtherDTO);
        //将数据分组
        //Map<String, List<SalesPlanOtherDTO>> paramMap = salesPlanDTOList.stream().collect(Collectors.groupingBy(SalesPlanOtherDTO::getCondition, Collectors.toList()));
        //全部数据导出
        //exportDataList = this.getExcelTargetList(paramMap, salesPlanOtherDTO, allTargetsDesc, dateTitles, level);
        exportDataList = this.getExcelList(salesPlan, allTargetsDesc, dateTitles);
        //获取所有查询条件标识
        //List<String> conditions = this.getConditions(salesPlanOtherDTO);
        //获取excel标题 同时返回高级搜索标题的数量
        List<List<String>> heads = new ArrayList<>();
        int mergeCellsColumns = this.setExcelTitles(heads, dateTitles);
        return ExcelExportUtil.getExcelExportData(mergeCellsColumns, exportDataList, heads, allTargetsDesc.size(), new GeneralCellWriteHandler());
    }

    @Override
    public ExcelExportDataDTO downLoadTemplate(String type) throws Exception {
        // 获取日期标题
        List<String> dateTitles = getTitleByDate(type);
        //获取上次导入的计划数据
        List<SalesWriteDTO> salesList = getLastWeekByType(type);
        //转换为导入模板的数据
        List<List<Object>> exportDataList = getExcelData(salesList, type);

        //获取excel标题 同时返回高级搜索标题的数量
        List<List<String>> heads = new ArrayList<>();
        setExcelTitle(heads, type, dateTitles);
        return ExcelExportUtil.getExcelExportData(exportDataList, heads, new GeneralCellWriteHandler());
    }


    */
/**
     * 修改确认量
     *
     * @param ids
     * @param unitType
     * @param userId
     * @return
     *//*

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean confirm(List<SalesPlanOtherUpdateDTO> ids, Long unitType, Long userId) {
        List<String> idList = new ArrayList<>();
        ids.forEach(item -> {
            idList.add(item.getId());
        });
        //获取当前用户角色权限
        List<SalesPlanPermissionsDTO> roleAreaList = getRoleAreaList(userId);
        //一个用户只有一个级别（1:渠道、渠道下级（1级导入，确认），2：全渠道（2级确认））
        Integer level = roleAreaList.get(0).getPermissionsLevel();
        //根据ID集合获取其他渠道计划集合
        List<SalesPlanOtherDTO> dtoList = null;//salesPlanOtherRespository.getListById(idList);
        //根据单位类型换算比例
        List<String> skuCodeList = dtoList.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList());
        List<SkuUnitDTO> skuUnit = itemCoreFacade.getConversionRatio(skuCodeList, unitType);
        List<SalesPlanOtherDTO> salesList = new ArrayList<>();
        try {
            //拆分确认量
            ids.forEach(item -> {
                //ID唯一
                SalesPlanOtherDTO otherDto = dtoList.stream().filter(dto -> dto.getId().equals(item.getId())).collect(Collectors.toList()).get(0);
                SalesPlanOtherDTO saleDto = new SalesPlanOtherDTO();
                BigDecimal confirmQty = item.getConfirmQtys();
                if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                    saleDto.setAllchannelConfirmedQty(confirmQty);
                } else {
                    saleDto.setChannelConfirmedQty(confirmQty);
                    saleDto.setConfirmedQty(confirmQty);
                }
                //saleDto.setId(item.getId());
                saleDto.setSkuCode(otherDto.getSkuCode());
                saleDto.setVersionNo(otherDto.getVersionNo());
                saleDto.setCreator(userId);
                saleDto.setCreatorName(userId.toString());
                salesList.add(saleDto);
            });
            //转换成基本单位
            this.calculationProBySaleConfirm(salesList, skuUnit, level);
            salesPlanOtherRespository.updateConfirm(salesList);
        } catch (Exception e) {
            throw new RomeException(ResponseMsg.FAIL.getCode(), ResponseMsg.FAIL.getMsg());
        }
        return Boolean.TRUE;
    }

    */
/**
     * 从营销中心获取数据新增到其他渠道计划表
     *
     * @param dtoList
     *//*

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addPlanOtherData(List<SalesPlanOtherSimpleDTO> dtoList) {
        if (CollectionUtils.isEmpty(dtoList)) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2019.getCode(), ResponseMsg.PARAM_ERROR_2019.getMsg());
        }
        //单次导入不能超过10000行
        if (dtoList.size() > CommonConstants.PLAN_OTHER_IMPORT_MAX) {
            throw new RomeException(ResponseMsg.FAIL_2003.getCode(), ResponseMsg.FAIL_2003.getMsg());
        }
        dtoList.forEach(item -> {
            //活动编码必填
            if (ObjectUtil.isNull(item.getSalesPlanActivityNo())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2017.getCode(), ResponseMsg.PARAM_ERROR_2017.getMsg());
            }
            //渠道code必填
            if (ObjectUtil.isNull(item.getChannelCode())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2014.getCode(), ResponseMsg.PARAM_ERROR_2014.getMsg());
            }
            //省份不能为空
            if (ObjectUtil.isNull(item.getProvinceName())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2008.getCode(), ResponseMsg.PARAM_ERROR_2008.getMsg());
            }
            //商品编码必填
            if (ObjectUtil.isEmpty(item.getSkuCode())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2012.getCode(), ResponseMsg.PARAM_ERROR_2012.getMsg());
            }
            //商品数量或计划周期不能为空
            if (CollectionUtil.isNotEmpty(item.getList())) {
                if (ObjectUtil.isNull(item.getList().get(0).getConfirmedQty())) {
                    throw new RomeException(ResponseMsg.PARAM_ERROR_2013.getCode(), ResponseMsg.PARAM_ERROR_2013.getMsg());
                }
                if (ObjectUtil.isNull(item.getList().get(0).getPlanWeek())) {
                    throw new RomeException(ResponseMsg.PARAM_ERROR_2010.getCode(), ResponseMsg.PARAM_ERROR_2010.getMsg());
                }
            } else {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2011.getCode(), ResponseMsg.PARAM_ERROR_2010.getMsg());
            }
            //商品类型编码必填
            if (ObjectUtil.isNull(item.getSkuTypeCode())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2016.getCode(), ResponseMsg.PARAM_ERROR_2016.getMsg());
            }
            //单位不能为空
            if (ObjectUtil.isNull(item.getUnit())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2026.getCode(), ResponseMsg.PARAM_ERROR_2026.getMsg());
            }
        });
        //获取所有省份为江苏省的数据
        List<SalesPlanOtherSimpleDTO> simpleList = dtoList.stream().filter(item -> CommonConstants.PRO_NAME.contains(item.getProvinceName())).distinct().collect(Collectors.toList());
        simpleList.forEach(item -> {
            //省份为江苏省，城市不能为空
            if (ObjectUtil.isNull(item.getCityName())) {
                throw new RomeException(ResponseMsg.PARAM_ERROR_2009.getCode(), ResponseMsg.PARAM_ERROR_2009.getMsg());
            }
        });
        //需要拆分成门店的省份集合
        List<AreaDTO> provinceList = new ArrayList<>();
        //需要拆分成门店的城市集合
        List<AreaDTO> cityNameList = new ArrayList<>();
        //拆分门店对应的省名称集合
        List<AreaDTO> provinceNameListByCity = new ArrayList<>();
        //门店集合
        List<StoreDTO> storeList = new ArrayList<>();
        //门店对应的省份集合（不用拆分）
        List<AreaDTO> provinceListByStore = new ArrayList<>();
        //门店对应的城市集合（不用拆分）
        List<AreaDTO> cityListByStore = new ArrayList<>();
        //门店对应的县/区集合（不用拆分）
        List<AreaDTO> countyListByStore = new ArrayList<>();
        Boolean ifTrue;
        //获取所有不重复省份的名称
        List<String> provinceNams = dtoList.stream().map(SalesPlanOtherSimpleDTO::getProvinceName).distinct().collect(Collectors.toList());
        provinceList = baseDataFacade.listProvinceByList(provinceNams);
        ifTrue = provinceList.size() == provinceNams.size();
        if (!ifTrue) {
            List<String> proSt = provinceList.stream().map(AreaDTO::getName).collect(Collectors.toList());
            List<String> list = provinceNams.stream().filter(item -> !proSt.contains(item)).collect(Collectors.toList());
            throw new RomeException(ResponseMsg.FAIL_2043.getCode(), ResponseMsg.FAIL_2043.getMsg() + list);
        }
        //获取所有不重复城市的名称
        List<String> cityNames = dtoList.stream().filter(item -> ObjectUtil.isNotNull(item.getCityName())).map(SalesPlanOtherSimpleDTO::getCityName).distinct().collect(Collectors.toList());
        if (cityNames.size() > 0) {
            //根据城市名称获取城市信息
            cityNameList = baseDataFacade.listProvinceByList(cityNames);
            ifTrue = cityNameList.size() == cityNames.size();
            if (!ifTrue) {
                List<String> citySt = cityNameList.stream().map(AreaDTO::getName).collect(Collectors.toList());
                List<String> list = cityNames.stream().filter(item -> !citySt.contains(item)).collect(Collectors.toList());
                throw new RomeException(ResponseMsg.FAIL_2042.getCode(), ResponseMsg.FAIL_2042.getMsg() + list);
            }
            //获取省份编码
            List<String> provinces = cityNameList.stream().map(AreaDTO::getParentCode).collect(Collectors.toList());
            if (provinces.size() > 0) {
                provinceNameListByCity = baseDataFacade.listAreaInfoByCode(provinces);
            }
        }
        //获取所有不重复门店的编码
        List<String> storeCodes = dtoList.stream().filter(item -> ObjectUtil.isNotNull(item.getStoreCode())).map(SalesPlanOtherSimpleDTO::getStoreCode).distinct().collect(Collectors.toList());
        if (storeCodes.size() > 0) {
            //获取基础服务中心所有门店
            storeList = baseDataFacade.listStore(new StoreDTO()).getList();
            //筛选出表格中的门店
            storeList = storeList.stream().filter(f -> storeCodes.contains(f.getCode())).collect(Collectors.toList());
            List<String> stos = storeList.stream().map(StoreDTO::getCode).collect(Collectors.toList());
            List<String> noStoreList = storeCodes.stream().filter(item -> !stos.contains(item)).collect(Collectors.toList());
            if (noStoreList.size() > 0) {
                throw new RomeException(ResponseMsg.FAIL_2013.getCode(), ResponseMsg.FAIL_2013.getMsg() + ",错误门店code：" + noStoreList);
            }
            List<String> failDirectlyList = new ArrayList<>();
            List<String> failJoinList = new ArrayList<>();
            for (SalesPlanOtherSimpleDTO readDto : dtoList) {
                if (ObjectUtil.isNotNull(readDto.getStoreCode())) {
                    String channel = readDto.getChannelCode();
                    List<StoreDTO> storess = storeList.stream().filter(item -> item.getCode().equals(readDto.getStoreCode())).collect(Collectors.toList());
                    //如果为直营
                    if (channel.equals(ChannelTypeEnum.DIRECTLY_OPERATE.getCode())) {
                        if (!storess.get(0).getStoreProperties().equals(ShopTypeEnum.DIRECTLY_SHOP.getStoreProperties()) && !storess.get(0).getStoreProperties().equals(ShopTypeEnum.NON_BRANCH_SHOP.getStoreProperties()) && !storess.get(0).getStoreProperties().equals(ShopTypeEnum.POOL_SHOP.getStoreProperties())) {
                            failDirectlyList.add(readDto.getChannelCode() + "-" + readDto.getStoreCode());
                        }
                    } else {
                        if (!storess.get(0).getStoreProperties().equals(ShopTypeEnum.JOIN_SHOP.getStoreProperties()) && !storess.get(0).getStoreProperties().equals(ShopTypeEnum.JOIN_TRUSTEESHIP_SHOP.getStoreProperties())) {
                            failJoinList.add(readDto.getChannelCode() + "-" + readDto.getStoreCode());
                        }
                    }
                }
            }
            if (failDirectlyList.size() > 0) {
                throw new RomeException(ResponseMsg.FAIL_2905.getCode(), ResponseMsg.FAIL_2905.getMsg() + failDirectlyList);
            }
            if (failJoinList.size() > 0) {
                throw new RomeException(ResponseMsg.FAIL_2906.getCode(), ResponseMsg.FAIL_2906.getMsg() + failJoinList);
            }
            //获取不重复
            List<String> provinceCodes = storeList.stream().filter(f -> ObjectUtil.isNotNull(f.getProvinceCode())).map(StoreDTO::getProvinceCode).distinct().collect(Collectors.toList());
            List<String> cityCodes = storeList.stream().filter(f -> ObjectUtil.isNotNull(f.getCityCode())).map(StoreDTO::getCityCode).distinct().collect(Collectors.toList());
            List<String> countyCodes = storeList.stream().filter(f -> ObjectUtil.isNotNull(f.getAreaCode())).map(StoreDTO::getAreaCode).distinct().collect(Collectors.toList());
            //根据code批量获取省市区信息
            if (provinceCodes.size() > 0) {
                provinceListByStore = baseDataFacade.listAreaInfoByCode(provinceCodes);
            }
            if (cityCodes.size() > 0) {
                cityListByStore = baseDataFacade.listAreaInfoByCode(cityCodes);
            }
            if (countyCodes.size() > 0) {
                countyListByStore = baseDataFacade.listAreaInfoByCode(countyCodes);
            }
        }
        //获取导入数据中去重后的商品code集合
        List<String> skuCodeList = dtoList.stream().filter(item -> ObjectUtil.isNotNull(item.getSkuCode())).map(SalesPlanOtherSimpleDTO::getSkuCode).distinct().collect(Collectors.toList());
        //转换为基础单位
        List<SkuUnitExtDTO> skuUnitList = itemCoreFacade.getSkuUnitByCodeAndType(skuCodeList, 5);
        ifTrue = skuUnitList.size() == skuCodeList.size();
        if (!ifTrue) {
            List<String> skuSt = skuUnitList.stream().map(SkuUnitExtDTO::getSkuCode).collect(Collectors.toList());
            List<String> list = skuCodeList.stream().filter(item -> !skuSt.contains(item)).collect(Collectors.toList());
            throw new RomeException(ResponseMsg.FAIL_2033.getCode(), ResponseMsg.FAIL_2033.getMsg() + list);
        }
        //根据商品code集合获取商品对应品类id集合(接口最多一次只能调100个)
        List<SkuInfosDTO> skus = new ArrayList<>();
        int perThreadHandleCount = 100;
        int countNum = 0;
        while (countNum < skuCodeList.size()) {
            countNum += perThreadHandleCount;
            List<String> dtos = ImmutableList.copyOf(skuCodeList.subList(countNum - perThreadHandleCount,
                    countNum < skuCodeList.size() ? countNum : skuCodeList.size()));
            List<SkuInfosDTO> skuInfos = itemCoreFacade.getAllCategoryIdBySkuCode(1, dtos.size(), dtos).getList();
            skus.addAll(skuInfos);
        }
        ifTrue = skus.size() == skuCodeList.size();
        if (!ifTrue) {
            List<String> skuSt = skus.stream().map(SkuInfosDTO::getSkuCode).collect(Collectors.toList());
            List<String> list = skuCodeList.stream().filter(item -> !skuSt.contains(item)).collect(Collectors.toList());
            throw new RomeException(ResponseMsg.FAIL_2032.getCode(), ResponseMsg.FAIL_2032.getMsg() + list);
        }
        List<Integer> ids = skus.stream().filter(f -> ObjectUtil.isNotNull(f.getCategoryId())).map(SkuInfosDTO::getCategoryId).distinct().collect(Collectors.toList());
        //查询出所有商品code对应的品类信息
        List<CategorySimpleDTO> categorys = itemCoreFacade.getAllCategoryByCategoryId(ids);
        List<SalesPlanOtherDTO> saleList = this.getSaleList(dtoList, skus, categorys, provinceList, cityNameList, storeList,
                provinceListByStore, cityListByStore, countyListByStore,
                provinceNameListByCity, skuUnitList);
        List<SalesPlanOtherDTO> sales = new ArrayList<>();
        IdWorker idWorker = new IdWorker();
        saleList.parallelStream().collect(Collectors.groupingBy(o -> (o.getChannelCode() + o.getProvinceCode() + o.getPlanStartDate() + o.getSkuCode() + o.getType() + (ObjectUtil.isNotEmpty(o.getStoreCode()) ? o.getStoreCode() : "") + (ObjectUtil.isNotEmpty(o.getCityCode()) ? o.getCityCode() : "")), Collectors.toList())).forEach((k, v) -> {
            Long id = idWorker.getId();
            //优惠券不添加到总量里
            if (v.get(0).getSkuName().contains("优惠券")) {
                BigDecimal qty = v.stream().map(SalesPlanOtherDTO::getCouponQty).reduce(BigDecimal.ZERO, BigDecimal::add);
                v.get(0).setSalesPlanOtherNo(id + "");
                v.get(0).setCouponQty(qty);
            } else {
                BigDecimal reduce = v.stream().map(SalesPlanOtherDTO::getConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
                v.get(0).setSalesPlanOtherNo(id + "");
                v.get(0).setConfirmedQty(reduce);
                v.get(0).setChannelConfirmedQty(reduce);
                v.get(0).setAllchannelConfirmedQty(reduce);
            }
            v.get(0).setPlanImportDate(new Date());
            sales.add(v.get(0));
        });
        List<SalesPlanOtherDTO> salesList = new ArrayList<>();
        salesList = sales;
        //修改上次确认量
        updateLastDate(salesList,CommonConstants.FOUR);
        Integer size = 0;
        List<UnitCodeExtParamDTO> paramList = new ArrayList<>();
        for (SalesPlanOtherSimpleDTO simple : dtoList) {
            UnitCodeExtParamDTO param = new UnitCodeExtParamDTO();
            param.setSkuCode(simple.getSkuCode());
            param.setUnitName(simple.getUnit());
            paramList.add(param);
        }
        //去掉重复数据
        HashSet set = new HashSet(paramList);
        paramList.clear();
        paramList.addAll(set);
        List<SkuUnitDTO> skuUnitaList = itemCoreFacade.getUtilInfoBySkuCode(paramList);
        List<SkuUnitDTO> skuUnitListb = new ArrayList<>();
        //去重
        skuUnitaList.parallelStream().collect(Collectors.groupingBy(o -> (o.getSkuCode() + o.getUnitName() + o.getUnitCode() + o.getScale()), Collectors.toList())).forEach((k, v) -> {
            skuUnitListb.add(v.get(0));
        });
        this.calculationProBySale(salesList, skuUnitListb);
        //处理单位(查出销售单位换算比例)
        List<SkuUnitDTO> skuUnitLista = itemCoreFacade.getConversionRatio(skuCodeList, SkuUnitTypeEnum.SALES_UNIT.getUnitType());
        this.calculationProBySale(salesList, skuUnitLista);
        //处理单位(查出基础单位换算比例)
        List<SkuUnitDTO> skuUnitListc = itemCoreFacade.getConversionRatio(skuCodeList, SkuUnitTypeEnum.BASIS_UNIT.getUnitType());
        this.calculationPro(salesList, skuUnitListc);
        */
/*SalesPlanOtherDTO dt = new SalesPlanOtherDTO();
        dt.setSkuCodeList(salesList.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList()));
        dt.setTypeList(salesList.stream().map(SalesPlanOtherDTO::getType).distinct().collect(Collectors.toList()));
        //门店code只有直营渠道、加盟存在
        List<String> storeCodeList = salesList.stream().filter(item -> ObjectUtil.isNotNull(item.getStoreCode())).map(SalesPlanOtherDTO::getStoreCode).distinct().collect(Collectors.toList());
        dt.setStoreCodeList(storeCodeList);
        dt.setFatherChannelCodeList(salesList.stream().map(SalesPlanOtherDTO::getChannelCode).distinct().collect(Collectors.toList()));
        dt.setPlanStartDateList(salesList.stream().map(SalesPlanOtherDTO::getPlanStartDate).distinct().collect(Collectors.toList()));
        dt.setProvinceCodeList(salesList.stream().map(SalesPlanOtherDTO::getProvinceCode).distinct().collect(Collectors.toList()));
        dt.setCityCodeList(salesList.stream().filter(item -> ObjectUtil.isNotNull(item.getCityCode())).map(SalesPlanOtherDTO::getCityCode).distinct().collect(Collectors.toList()));
        dt.setCountyCodeList(salesList.stream().filter(item -> ObjectUtil.isNotNull(item.getCityCode())).map(SalesPlanOtherDTO::getCountyCode).distinct().collect(Collectors.toList()));
        //查询数据库是否存在导入数据
        List<SalesPlanOtherDTO> dateLists = salesPlanOtherRespository.getRepeats(dt);*//*

        List<Date> startDateList = salesList.stream().map(SalesPlanOtherDTO::getPlanStartDate).distinct().collect(Collectors.toList());
        List<Date> endDateList = salesList.stream().map(SalesPlanOtherDTO::getPlanEndDate).distinct().collect(Collectors.toList());
        List<SalesPlanOtherDTO> dateLists = dealData(salesList, Collections.min(startDateList), Collections.max(endDateList));
        if (CollectionUtils.isNotEmpty(dateLists)) {
            List<SalesPlanOtherDTO> updateList = new ArrayList<>();
            List<SalesPlanOtherDTO> insertList = new ArrayList<>();
            for (SalesPlanOtherDTO dtoa : salesList) {
                List<SalesPlanOtherDTO> repeats = dateLists.stream().filter(item ->
                        item.getChannelCode().equals(dtoa.getChannelCode()) &&
                                item.getType().equals(dtoa.getType()) &&
                                item.getProvinceCode().equals(dtoa.getProvinceCode()) &&
                                (ObjectUtil.isNull(dtoa.getCityCode()) ? true : (ObjectUtil.isNull(item.getCityCode()) ? false : item.getCityCode().equals(dtoa.getCityCode()))) &&
                                (ObjectUtil.isNull(dtoa.getStoreCode()) ? true : (ObjectUtil.isNull(item.getStoreCode()) ? false : item.getStoreCode().equals(dtoa.getStoreCode()))) &&
                                item.getSkuCode().equals(dtoa.getSkuCode()) &&
                                item.getPlanStartDate().compareTo(dtoa.getPlanStartDate()) == 0)
                        .collect(Collectors.toList());
                //说明同一个省份下有多条记录
                if (repeats.size() > 1) {
                    //如果只有省
                    if (ObjectUtil.isNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                        //过滤去掉城市和门店为空的省份数据
                        repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                && ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                    //如果有省和城市
                    else if (ObjectUtil.isNotNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                        //过滤去掉门店为空的数据
                        repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                }
                if (repeats.size() == 1) {
                    SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                    SalesPlanOtherDTO dtob = repeats.get(0);
                    dto.setId(dtob.getId());
                    dto.setSalesPlanOtherNo(dtob.getSalesPlanOtherNo());
                    dto.setVersionNo(dtob.getVersionNo());
                    dto.setConfirmedQty(dtoa.getConfirmedQty());
                    dto.setChannelConfirmedQty(dtoa.getConfirmedQty());
                    dto.setAllchannelConfirmedQty(dtoa.getConfirmedQty());
                    dto.setPlanImportDate(new Date());
                    dto.setCreator(1L);
                    dto.setCreatorName("营销中心修改");
                    updateList.add(dto);
                } else {
                    insertList.add(dtoa);
                }
            }
            if (updateList.size() > 0) {
                //异步修改数据到ES
                startUpdate(updateList);
                salesPlanOtherRespository.updateAll(updateList);
            }
            salesList = insertList;
            if (insertList.size() > 0) {
                //异步新增数据到ES
                startInsert(insertList);
                size = salesPlanOtherRespository.addPlanOtherData(salesList);
            }
        } else {
            //异步新增数据到ES
            startInsert(salesList);
            size = salesPlanOtherRespository.addPlanOtherData(salesList);
        }

        if (size == salesList.size()) {
            return Boolean.TRUE;
        } else {
            throw new RomeException(ResponseMsg.FAIL.getCode(), ResponseMsg.FAIL.getMsg());
        }
    }

    */
/**
     * 批量修改其他渠道计划状态（营销计划）
     *
     * @param numbers
     *//*

    @Override
    public Boolean updatePlanOtherType(List<String> numbers) {
        if (CollectionUtils.isEmpty(numbers)) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2017.getCode(), ResponseMsg.PARAM_ERROR_2017.getMsg());
        }
        List<SalesPlanOtherDTO> saleslist = new ArrayList<>();
        //根据活动计划编号获取可以修改的数据
        List<SalesPlanOtherDTO> dtoList = salesPlanOtherRespository.getListByNumbers(numbers);
        if (dtoList.size() == 0) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2022.getCode(), ResponseMsg.PARAM_ERROR_2022.getMsg());
        }
        List<String> statusList = dtoList.stream().filter(item -> CommonConstants.ZERO == item.getStatus()).map(SalesPlanOtherDTO::getSalesPlanActivityNo).distinct().collect(Collectors.toList());
        if (statusList.size() > 0) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2034.getCode(), ResponseMsg.PARAM_ERROR_2034.getMsg() + statusList);
        }
        List<String> statusLists = dtoList.stream().filter(item -> ObjectUtil.isNotNull(item.getSynStatus()) && CommonConstants.ONE == item.getSynStatus()).map(SalesPlanOtherDTO::getSalesPlanActivityNo).distinct().collect(Collectors.toList());
        if (statusLists.size() > 0) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2035.getCode(), ResponseMsg.PARAM_ERROR_2035.getMsg() + statusLists);
        }
        dtoList.forEach(item -> {
            item.setCreator(1L);
            item.setCreatorName("营销中心修改状态");
            item.setId(item.getId());
            item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
            item.setStatus(CommonConstants.ZERO);
            saleslist.add(item);
        });
        if (saleslist.size() == 0) {
            throw new RomeException(ResponseMsg.PARAM_ERROR_2034.getCode(), ResponseMsg.PARAM_ERROR_2034.getMsg());
        }
        //异步修改数据到ES
        startUpdate(saleslist);
        Integer size = salesPlanOtherRespository.updatePlanOtherType(saleslist);
        if (size > 0) {
            return Boolean.TRUE;
        } else {
            throw new RomeException(ResponseMsg.FAIL.getCode(), ResponseMsg.FAIL.getMsg());
        }
    }

    */
/**
     * 导入批量新增
     *
     * @param dtos
     * @return
     *//*

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer importPlanType(List<SalesPlanOtherDTO> dtos, Integer type) {
        //修改上次计划量、上次确认量数据
        updateLastDate(dtos, type);
        String opSign = dtos.get(0).getOpSign();
        Long modifier = dtos.get(0).getModifier();
        String modifierName = dtos.get(0).getModifierName();
        */
/*dt.setSkuCodeList(dtos.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList()));
        dt.setTypeList(dtos.stream().map(SalesPlanOtherDTO::getType).distinct().collect(Collectors.toList()));
        //门店code只有直营渠道、加盟存在
        List<String> storeCodeList = dtos.stream().filter(item -> ObjectUtil.isNotNull(item.getStoreCode())).map(SalesPlanOtherDTO::getStoreCode).distinct().collect(Collectors.toList());
        dt.setStoreCodeList(storeCodeList);
        dt.setFatherChannelCodeList(dtos.stream().map(SalesPlanOtherDTO::getChannelCode).distinct().collect(Collectors.toList()));
        dt.setPlanStartDateList(dtos.stream().map(SalesPlanOtherDTO::getPlanStartDate).distinct().collect(Collectors.toList()));
        dt.setProvinceCodeList(dtos.stream().map(SalesPlanOtherDTO::getProvinceCode).distinct().collect(Collectors.toList()));
        dt.setCityCodeList(dtos.stream().map(SalesPlanOtherDTO::getCityCode).distinct().collect(Collectors.toList()));*//*

        //查询数据库是否存在导入数据
        //处理重复数据（转换为）
        List<SalesPlanOtherDTO> dateLists = dealData(dtos, null, null);
        List<SalesPlanOtherDTO> updateList = new ArrayList<>();
        List<SalesPlanOtherDTO> insertList = new ArrayList<>();
        //获取所有不重复的商品code
        List<String> skuCodeList = dtos.stream().filter(item -> ObjectUtil.isNotNull(item.getSkuCode())).map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList());
        //处理单位(查出销售单位换算比例)
        List<SkuUnitDTO> skuUnitLista = new ArrayList<>();
        //统一销售单位
        skuUnitLista = itemCoreFacade.getConversionRatio(skuCodeList, SkuUnitTypeEnum.SALES_UNIT.getUnitType());
        //如果获取商品比例数量与导入商品数量不一致，提示转换失败
        if (skuCodeList.size() != skuUnitLista.size()) {
            List<String> skuUnits = skuUnitLista.stream().map(SkuUnitDTO::getSkuCode).collect(Collectors.toList());
            List<String> reduce = skuCodeList.stream().filter(item -> !skuUnits.contains(item)).collect(Collectors.toList());
            throw new RomeException("9999", "商品转换销售单位比例失败" + ",商品编码为：" + reduce);
        }
        this.calculationProBySale(dtos, skuUnitLista);
        //处理单位(查出基础单位换算比例)
        List<SkuUnitDTO> skuUnitList = itemCoreFacade.getConversionRatio(skuCodeList, SkuUnitTypeEnum.BASIS_UNIT.getUnitType());
        this.calculationPro(dtos, skuUnitList);
        Integer result = 0;
        // 开始时间
        long start = System.currentTimeMillis();
        //导入销售计划
        if (type == 1) {
            //获取上次（前1周）的数量
            */
/*List<SalesPlanOtherDTO> lastDateList = new ArrayList<>();
            dtos.forEach(item -> {
                SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                dto.setPlanStartDate(MyDateUtil.getLastDate(item.getPlanStartDate()));
                lastDateList.add(dto);
            });
            dt.setPlanStartDateList(lastDateList.stream().map(SalesPlanOtherDTO::getPlanStartDate).collect(Collectors.toList()));
            //查询数据库是否存在上次（前1周）的销售计划数据集合
            List<SalesPlanOtherDTO> lastDateLists = salesPlanOtherRespository.getRepeats(dt);
            Map<Date, List<SalesPlanOtherDTO>> map = new HashMap<>();
            if (CollectionUtils.isNotEmpty(lastDateLists)) {
                lastDateLists.forEach(item -> {
                    map.put(item.getPlanStartDate(), lastDateLists);
                });
            }*//*

            //不为空说明导入有重复数据
            if (CollectionUtils.isNotEmpty((dateLists))) {
                for (SalesPlanOtherDTO dtoa : dtos) {
                    //判断
                    List<SalesPlanOtherDTO> repeats = dateLists.stream().filter(item ->
                            item.getChannelCode().equals(dtoa.getChannelCode()) &&
                                    item.getType().equals(dtoa.getType()) &&
                                    item.getProvinceCode().equals(dtoa.getProvinceCode()) &&
                                    (ObjectUtil.isNull(dtoa.getCityCode()) ? true : (ObjectUtil.isNull(item.getCityCode()) ? false : item.getCityCode().equals(dtoa.getCityCode()))) &&
                                    (ObjectUtil.isNull(dtoa.getStoreCode()) ? true : (ObjectUtil.isNull(item.getStoreCode()) ? false : item.getStoreCode().equals(dtoa.getStoreCode()))) &&
                                    item.getSkuCode().equals(dtoa.getSkuCode()) &&
                                    item.getPlanStartDate().compareTo(dtoa.getPlanStartDate()) == 0)
                            .collect(Collectors.toList());
                    //说明同一个省份下有多条记录
                    if (repeats.size() > 1) {
                        //如果只有省
                        if (ObjectUtil.isNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                            //过滤去掉城市和门店为空的省份数据
                            repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                    && ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                        }
                        //如果有省和城市
                        else if (ObjectUtil.isNotNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                            //过滤去掉门店为空的数据
                            repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                        }
                    }
                    //修改
                    if (repeats.size() == 1) {
                        SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                        SalesPlanOtherDTO dtob = repeats.get(0);
                        dto.setId(dtob.getId());
                        dto.setSalesPlanOtherNo(dtob.getSalesPlanOtherNo());
                        dto.setSkuCode(dtob.getSkuCode());
                        dto.setVersionNo(dtob.getVersionNo());
                        //重复的数据,数据量覆盖
                        dto.setPlanQty(dtoa.getPlanQty());
                        dto.setConfirmedQty(dtoa.getPlanQty());
                        dto.setCreator(dtoa.getCreator());
                        dto.setCreatorName(dtoa.getCreatorName());
                        dto.setOpSign(opSign);
                        dto.setPlanImportDate(new Date());
                        updateList.add(dto);
                        */
/*if (map.size() > 0) {
                            map.forEach((k, v) -> {
                                //如果日期等于前1周日期，更新上次计划量、上次确认量
                                if (DateUtil.betweenWeek(k, dtob.getPlanStartDate(), true) == 1) {
                                    List<SalesPlanOtherDTO> salesList = v.stream().filter(item -> item.getChannelCode().equals(dtob.getChannelCode()) &&
                                            item.getType().equals(dtob.getType()) && item.getSkuCode().equals(dtob.getSkuCode()) &&
                                            (ObjectUtil.isNotNull(item.getStoreCode()) ? item.getStoreCode().equals(dtob.getStoreCode()) : true) &&
                                            item.getPlanStartDate().compareTo(k) == 0)
                                            .collect(Collectors.toList());
                                    if (salesList.size() == 1) {
                                        dto.setLastPlanQty(salesList.get(0).getPlanQty());
                                        dto.setLastConfirmedQty(salesList.get(0).getConfirmedQty());
                                        dto.setChannelLastConfirmedQty(salesList.get(0).getChannelConfirmedQty());
                                        dto.setAllchannelLastConfirmedQty(salesList.get(0).getAllchannelConfirmedQty());
                                    }
                                }
                            });
                        }*//*

                    } else {
                        */
/*if (map.size() > 0) {
                            map.forEach((k, v) -> {
                                if (DateUtil.betweenWeek(k, dtoa.getPlanStartDate(), true) == 1) {
                                    List<SalesPlanOtherDTO> salesList = v.stream().filter(item -> item.getChannelCode().equals(dtoa.getChannelCode()) &&
                                            item.getType().equals(dtoa.getType()) &&
                                            item.getSkuCode().equals(dtoa.getSkuCode()) &&
                                            (ObjectUtil.isNotNull(item.getStoreCode()) ? item.getStoreCode().equals(dtoa.getStoreCode()) : true) &&
                                            item.getPlanStartDate().compareTo(k) == 0).collect(Collectors.toList());
                                    if (salesList.size() == 1) {
                                        dtoa.setLastPlanQty(salesList.get(0).getPlanQty());
                                        dtoa.setLastConfirmedQty(salesList.get(0).getConfirmedQty());
                                        dtoa.setChannelLastConfirmedQty(salesList.get(0).getChannelConfirmedQty());
                                        dtoa.setAllchannelLastConfirmedQty(salesList.get(0).getAllchannelConfirmedQty());
                                    }
                                }
                            });
                        }*//*

                        insertList.add(dtoa);
                    }
                }
                if (updateList.size() > 0) {
                    //异步修改数据到ES
                    startUpdate(updateList);
                    salesPlanOtherRespository.updateAll(updateList);
                }
                dtos = insertList;
                if (insertList.size() > 0) {
                    //异步新增数据到ES
                    startInsert(insertList);
                    if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                        result = salesPlanOtherRespository.addPlanOtherData(dtos);
                    } else {
                        //新增数据异步处理
                        startThread(dtos);
                    }
                }
            } else {
                //异步新增数据到ES
                startInsert(dtos);
                if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                    result = salesPlanOtherRespository.addPlanOtherData(dtos);
                } else {
                    //新增数据异步处理
                    startThread(dtos);
                }
            }
        } else if (type == 2) {
            //新开店
            //不为空说明导入有重复数据
            if (CollectionUtils.isNotEmpty((dateLists))) {
                for (SalesPlanOtherDTO dtoa : dtos) {
                    //判断是否重复
                    List<SalesPlanOtherDTO> repeats = dateLists.stream().filter(item ->
                            item.getType().equals(dtoa.getType())
                                    && item.getChannelCode().equals(dtoa.getChannelCode())
                                    && item.getProvinceCode().equals(dtoa.getProvinceCode())
                                    && (ObjectUtil.isNull(dtoa.getCityCode()) ? true : (ObjectUtil.isNull(item.getCityCode()) ? false : item.getCityCode().equals(dtoa.getCityCode())))
                                    && item.getSkuCode().equals(dtoa.getSkuCode())
                                    && item.getPlanStartDate().compareTo(dtoa.getPlanStartDate()) == 0)
                            .collect(Collectors.toList());

                    //说明同一个省份下有多条记录
                    if (repeats.size() > 1) {
                        //如果只有省
                        if (ObjectUtil.isNull(dtoa.getCityCode())) {
                            //过滤去掉城市和门店为空的省份数据
                            repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                            ).collect(Collectors.toList());
                        }
                    }
                    //修改
                    if (repeats.size() == 1) {
                        SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                        SalesPlanOtherDTO dtob = repeats.get(0);
                        dto.setId(dtob.getId());
                        dto.setSalesPlanOtherNo(dtob.getSalesPlanOtherNo());
                        dto.setSkuCode(dtoa.getSkuCode());
                        dto.setVersionNo(dtoa.getVersionNo());
                        dto.setPlanImportDate(new Date());
                        //优惠券单独存着，不统计
                        if (dtob.getSkuName().contains("优惠券")) {
                            //重复的数据,数据量覆盖
                            dto.setCouponQty(dtoa.getCouponQty());
                        } else {
                            //重复的数据,数据量覆盖
                            dto.setConfirmedQty(dtoa.getConfirmedQty());
                            dto.setChannelConfirmedQty(dtoa.getChannelConfirmedQty());
                            dto.setAllchannelConfirmedQty(dtoa.getAllchannelConfirmedQty());
                        }
                        dto.setCreator(dtoa.getCreator());
                        dto.setCreatorName(dtoa.getCreatorName());
                        dto.setOpSign(opSign);
                        updateList.add(dto);
                    } else {
                        //新增
                        insertList.add(dtoa);
                    }
                }
                if (updateList.size() > 0) {
                    //异步修改数据到ES
                    startUpdate(updateList);
                    salesPlanOtherRespository.updateAll(updateList);
                }
                dtos = insertList;
                if (insertList.size() > 0) {
                    //异步新增数据到ES
                    startInsert(insertList);
                    if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                        result = salesPlanOtherRespository.addPlanOtherData(dtos);
                    } else {
                        startThread(dtos);
                    }
                }
            } else {
                //异步新增数据到ES
                startInsert(dtos);
                if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                    result = salesPlanOtherRespository.addPlanOtherData(dtos);
                } else {
                    //新增数据异步处理
                    startThread(dtos);
                }
            }

        } else {
            //新品铺货
            //不为空说明导入有重复数据
            if (CollectionUtils.isNotEmpty((dateLists))) {
                for (SalesPlanOtherDTO dtoa : dtos) {
                    List<SalesPlanOtherDTO> repeats = new ArrayList<>();
                    //直营、加盟可能会有门店
                    repeats = dateLists.stream().filter(item ->
                            item.getType().equals(dtoa.getType())
                                    && item.getChannelCode().equals(dtoa.getChannelCode())
                                    && item.getSkuCode().equals(dtoa.getSkuCode())
                                    && item.getPlanStartDate().compareTo(dtoa.getPlanStartDate()) == 0
                                    && item.getProvinceCode().equals(dtoa.getProvinceCode())
                                    && (ObjectUtil.isNull(dtoa.getCityCode()) ? true : (ObjectUtil.isNull(item.getCityCode()) ? false : item.getCityCode().equals(dtoa.getCityCode())))
                                    && (ObjectUtil.isNull(dtoa.getStoreCode()) ? true : (ObjectUtil.isNull(item.getStoreCode()) ? false : item.getStoreCode().equals(dtoa.getStoreCode()))))
                            .collect(Collectors.toList());
                    //说明同一个省份下有多条记录
                    if (repeats.size() > 1) {
                        //如果只有省
                        if (ObjectUtil.isNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                            //过滤去掉城市和门店为空的省份数据
                            repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                    && ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                        }
                        //如果有省和城市
                        else if (ObjectUtil.isNotNull(dtoa.getCityCode()) && ObjectUtil.isNull(dtoa.getStoreCode())) {
                            //过滤去掉门店为空的数据
                            repeats = repeats.stream().filter(repeat -> ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                        }
                    }
                    //修改
                    if (repeats.size() == 1) {
                        SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                        SalesPlanOtherDTO dtob = repeats.get(0);
                        dto.setId(dtob.getId());
                        dto.setSalesPlanOtherNo(dtob.getSalesPlanOtherNo());
                        dto.setSkuCode(dtob.getSkuCode());
                        dto.setPlanImportDate(new Date());
                        dto.setVersionNo(dtob.getVersionNo());
                        //重复的数据,数据量覆盖
                        dto.setConfirmedQty(dtoa.getConfirmedQty());
                        dto.setChannelConfirmedQty(dtoa.getChannelConfirmedQty());
                        dto.setAllchannelConfirmedQty(dtoa.getAllchannelConfirmedQty());
                        dto.setCreator(dtoa.getCreator());
                        dto.setCreatorName(dtoa.getCreatorName());
                        dto.setOpSign(opSign);
                        updateList.add(dto);
                    } else {
                        //新增
                        insertList.add(dtoa);
                    }
                }
                if (updateList.size() > 0) {
                    //异步修改数据到ES
                    startUpdate(updateList);
                    salesPlanOtherRespository.updateAll(updateList);
                }
                dtos = insertList;
                if (insertList.size() > 0) {
                    //异步新增数据到ES
                    startInsert(insertList);
                    if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                        result = salesPlanOtherRespository.addPlanOtherData(dtos);
                    } else {
                        startThread(dtos);
                    }
                }
            } else {
                //异步新增数据到ES
                startInsert(dtos);
                //小于1W条直接新增
                if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
                    result = salesPlanOtherRespository.addPlanOtherData(dtos);
                } else {
                    //新增数据异步处理
                    startThread(dtos);
                }
            }
        }
        //小于1W条直接新增
        if (dtos.size() < CommonConstants.PLAN_OTHER_IMPORT_MAX) {
            OperationLogRecordDTO operationDto = new OperationLogRecordDTO();
            operationDto.setOpSign(opSign);
            operationDto.setModifier(modifier);
            operationDto.setModifierName(modifierName);
            //新增成功或者修改成功
            if (result == dtos.size() || updateList.size() > 0) {
                operationDto.setOpTime((int) (System.currentTimeMillis() - start) + "ms");
                operationDto.setOpStatus(OperationStatusEnum.SUCCESS.getType());
                operationLogRecordRepository.updateOperationLogStatus(operationDto);
                return OperationStatusEnum.SUCCESS.getType();
            } else {
                operationDto.setFailReason("导入失败");
                operationDto.setOpStatus(OperationStatusEnum.FAIL.getType());
                operationLogRecordRepository.updateOperationLogStatus(operationDto);
                return OperationStatusEnum.FAIL.getType();
            }
        } else {
            return OperationStatusEnum.PROCESSING.getType();
        }
    }


    */
/**
     * 修改销售计划确认状态
     *
     * @return
     *//*

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateConfirmStatus() {
        //异步修改ES的计划确认状态
        startUpdateAll();
        Integer result = salesPlanOtherRespository.updateConfirmStatus();
        if (result > 0) {
            return Boolean.TRUE;
        } else {
            throw new RomeException(ResponseMsg.FAIL_2021.getCode(), ResponseMsg.FAIL_2021.getMsg());
        }
    }

    */
/**
     * 修改营销计划取消状态
     *
     * @return
     *//*

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateCancelStatus() {
        Integer result = salesPlanOtherRespository.updateCancelStatus();
        if (result > 0) {
            return Boolean.TRUE;
        } else {
            throw new RomeException(ResponseMsg.FAIL_2044.getCode(), ResponseMsg.FAIL_2044.getMsg());
        }
    }


    */
/**
     * 根据获取的换算比例计算指标数量(查询销售比例转换)
     *//*

    private List<SalesPlanOtherDTO> calculationPro(List<SalesPlanOtherDTO> resultList, List<SkuUnitDTO> skuUnitList) {
        if (CollectionUtils.isNotEmpty(skuUnitList) && CollectionUtils.isNotEmpty(resultList)) {
            skuUnitList.forEach(skuUnit -> {
                resultList.forEach(item -> {
                    if (item.getSkuCode().equals(skuUnit.getSkuCode())) {
                        item.setCouponQty(ObjectUtil.isNotEmpty(item.getCouponQty()) ? item.getCouponQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        item.setPlanQty(ObjectUtil.isNotEmpty(item.getPlanQty()) ? item.getPlanQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        item.setConfirmedQty(ObjectUtil.isNotEmpty(item.getConfirmedQty()) ? item.getConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        item.setChannelConfirmedQty(ObjectUtil.isNotEmpty(item.getChannelConfirmedQty()) ? item.getChannelConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        item.setAllchannelConfirmedQty(ObjectUtil.isNotEmpty(item.getAllchannelConfirmedQty()) ? item.getAllchannelConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                    }
                });
            });
        }
        return resultList;
    }

    */
/**
     * 单位换算（查询）
     *
     * @param resultList
     * @param skuUnitList
     * @return
     *//*

    private List<SalesPlanOtherInfoDTO> calculationProBySelect(List<SalesPlanOtherInfoDTO> resultList, List<SkuUnitDTO> skuUnitList) {
        if (CollectionUtils.isNotEmpty(skuUnitList) && CollectionUtils.isNotEmpty(resultList)) {
            skuUnitList.forEach(skuUnit -> {
                resultList.forEach(item -> {
                    List<BigDecimal> lastPlanQtys = new ArrayList<>();
                    List<BigDecimal> lastConfirmedQtys = new ArrayList<>();
                    List<BigDecimal> planQtys = new ArrayList<>();
                    List<BigDecimal> confirmedQtys = new ArrayList<>();
                    List<BigDecimal> subordinateConfirmedQtys = new ArrayList<>();
                    List<BigDecimal> planDifferences = new ArrayList<>();
                    if (item.getSkuCode().equals(skuUnit.getSkuCode())) {
                        item.getLastPlanQtys().forEach(qty -> {
                            lastPlanQtys.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                        });
                        item.getLastConfirmedQtys().forEach(qty -> {
                            lastConfirmedQtys.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                        });
                        item.getPlanQtys().forEach(qty -> {
                            planQtys.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                        });
                        item.getConfirmedQtys().forEach(qty -> {
                            confirmedQtys.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                        });
                        if (CollectionUtils.isNotEmpty(item.getSubordinateConfirmedQtys())) {
                            item.getSubordinateConfirmedQtys().forEach(qty -> {
                                subordinateConfirmedQtys.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                            });
                        }
                        item.getPlanDifferences().forEach(qty -> {
                            planDifferences.add((qty.compareTo(BigDecimal.ZERO) != 0 ? qty.divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO));
                        });
                        item.setLastPlanQtys(lastPlanQtys);
                        item.setLastConfirmedQtys(lastConfirmedQtys);
                        item.setPlanQtys(planQtys);
                        item.setConfirmedQtys(confirmedQtys);
                        item.setSubordinateConfirmedQtys(subordinateConfirmedQtys);
                        item.setPlanDifferences(planDifferences);
                    }
                });
            });
        }
        return resultList;
    }


    */
/**
     * 根据获取的换算比例计算指标数量(查询基础单位比例转换)
     *//*

    private List<SalesPlanOtherDTO> calculationProBySale(List<SalesPlanOtherDTO> resultList, List<SkuUnitDTO> skuUnitList) {
        if (CollectionUtils.isNotEmpty(skuUnitList) && CollectionUtils.isNotEmpty(resultList)) {
            skuUnitList.forEach(skuUnit -> {
                resultList.forEach(item -> {
                    if (item.getSkuCode().equals(skuUnit.getSkuCode())) {
                        item.setCouponQty(ObjectUtil.isNotEmpty(item.getCouponQty()) ? item.getCouponQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        item.setPlanQty(ObjectUtil.isNotEmpty(item.getPlanQty()) ? item.getPlanQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        item.setConfirmedQty(ObjectUtil.isNotEmpty(item.getConfirmedQty()) ? item.getConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        item.setChannelConfirmedQty(ObjectUtil.isNotEmpty(item.getChannelConfirmedQty()) ? item.getChannelConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        item.setAllchannelConfirmedQty(ObjectUtil.isNotEmpty(item.getAllchannelConfirmedQty()) ? item.getAllchannelConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                    }
                });
            });
        }
        return resultList;
    }

    */
/**
     * 根据获取的换算比例计算指标数量(查询销售比例转换)(页面修改用)
     *//*

    private List<SalesPlanOtherDTO> calculationProConfirm(List<SalesPlanOtherDTO> resultList, List<SkuUnitDTO> skuUnitList, Integer level) {
        if (CollectionUtils.isNotEmpty(skuUnitList) && CollectionUtils.isNotEmpty(resultList)) {
            skuUnitList.forEach(skuUnit -> {
                resultList.forEach(item -> {
                    if (item.getSkuCode().equals(skuUnit.getSkuCode())) {
                        if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                            item.setAllchannelConfirmedQty(ObjectUtil.isNotEmpty(item.getAllchannelConfirmedQty()) ? item.getAllchannelConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        }  else {
                            item.setChannelConfirmedQty(ObjectUtil.isNotEmpty(item.getChannelConfirmedQty()) ? item.getChannelConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                            item.setConfirmedQty(ObjectUtil.isNotEmpty(item.getConfirmedQty()) ? item.getConfirmedQty().divide(BigDecimal.valueOf(skuUnit.getScale()), 7, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
                        }
                    }
                });
            });
        }
        return resultList;
    }


    */
/**
     * 根据获取的换算比例计算指标数量(查询基础单位比例转换)(页面修改用)
     *//*

    private List<SalesPlanOtherDTO> calculationProBySaleConfirm(List<SalesPlanOtherDTO> resultList, List<SkuUnitDTO> skuUnitList, Integer level) {
        if (CollectionUtils.isNotEmpty(skuUnitList) && CollectionUtils.isNotEmpty(resultList)) {
            skuUnitList.forEach(skuUnit -> {
                resultList.forEach(item -> {
                    if (item.getSkuCode().equals(skuUnit.getSkuCode())) {
                        if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                            item.setAllchannelConfirmedQty(ObjectUtil.isNotEmpty(item.getAllchannelConfirmedQty()) ? item.getAllchannelConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        } else {
                            item.setChannelConfirmedQty(ObjectUtil.isNotEmpty(item.getChannelConfirmedQty()) ? item.getChannelConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                            item.setConfirmedQty(ObjectUtil.isNotEmpty(item.getConfirmedQty()) ? item.getConfirmedQty().multiply(BigDecimal.valueOf(skuUnit.getScale())) : BigDecimal.ZERO);
                        }
                    }
                });
            });
        }
        return resultList;
    }

    */
/* 设置分组依据的key值
     *
     * @param salesPlanOtherPlans 其他渠道计划dos
     * @param skuCodeList         sku代码列
     *     /**
     *  表
     * @return {@link List<SalesPlanOtherDTO>}
     *//*

    public List<SalesPlanOtherDTO> getGroupByKey(List<SalesPlanOtherDTO> salesPlanOtherPlans, SalesPlanOtherDTO salesPlanOther) {
        salesPlanOtherPlans.forEach(item -> {
            StringBuilder keyStr = new StringBuilder();
            keyStr.append(ObjectUtil.isNotNull(item.getChannelCode()) ? item.getChannelCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getSubChannelCode()) ? item.getSubChannelCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getPriCategoryCode()) ? item.getPriCategoryCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getSecCategoryCode()) ? item.getSecCategoryCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getTerCategoryCode()) ? item.getTerCategoryCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getProvinceCode()) ? item.getProvinceCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getCityCode()) ? item.getCityCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getCountyCode()) ? item.getCountyCode() : "");
            keyStr.append(ObjectUtil.isNotNull(item.getType()) ? item.getType() : "");
            if (CollectionUtils.isNotEmpty(salesPlanOther.getStoreCodeList())) {
                keyStr.append(ObjectUtil.isNotNull(item.getStoreCode()) ? item.getStoreCode() : "");
            }
            if (CollectionUtils.isNotEmpty(salesPlanOther.getSkuCodeList())) {
                keyStr.append(ObjectUtil.isNotNull(item.getSkuCode()) ? item.getSkuCode() : "");
            }
            item.setCondition(keyStr.toString());
        });
        return salesPlanOtherPlans;
    }

    */
/**
     * 汇总分组后的数据
     *
     * @param paramMap       参数映射
     * @param salesPlanOther 其他渠道计划
     * @param level          级别
     * @return {@link List<SalesPlanOtherInfoDTO>}
     *//*

    private List<SalesPlanOtherInfoDTO> getTargetList(Map<String, List<SalesPlanOtherDTO>> paramMap, SalesPlanOtherDTO salesPlanOther, Integer level*/
/*, List<SalesPlanOtherTypeDTO> typeList, List<SalesPlanOtherTypeDTO> typeImpList*//*
) {
        List<SalesPlanOtherInfoDTO> salesPlanOtherInfoList = new ArrayList<>();
        List<Map<String, Date>> weekDateList = salesPlanOther.getWeekDateList();
        //将分组后的数据汇总
        paramMap.keySet().forEach(key -> {
            //上次计划量
            List<BigDecimal> lastPlanQtys = new ArrayList<>();
            //上次确认量
            List<BigDecimal> lastConfirmedQtys = new ArrayList<>();
            //计划量
            List<BigDecimal> planQtys = new ArrayList<>();
            //确认量
            List<BigDecimal> confirmedQtys = new ArrayList<>();
            //下级确认量
            List<BigDecimal> subordinateConfirms = new ArrayList<>();
            //计划差异
            List<BigDecimal> planDifferences = new ArrayList<>();
            //计划比例
            List<BigDecimal> planProportions = new ArrayList<>();
            //渠道确认量
            List<BigDecimal> channelConfirmedQtys = new ArrayList<>();
            //全渠道确认量
            List<BigDecimal> allchannelConfirmedQtys = new ArrayList<>();
            //渠道上次确认量
            List<BigDecimal> channelLastConfirmedQtys = new ArrayList<>();
            //全渠道上次确认量
            List<BigDecimal> allchannelLastConfirmedQtys = new ArrayList<>();
            SalesPlanOtherInfoDTO salesPlanOtherInfo = new SalesPlanOtherInfoDTO();
            // 设置上次计划量
            weekDateList.forEach(date -> lastPlanQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getLastPlanQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            salesPlanOtherInfo.setLastPlanQtyLabel(SalesPlanOtherEnum.LAST_PLAN_QTY.getDesc());
            salesPlanOtherInfo.setLastPlanQtys(lastPlanQtys);
            // 设置计划量(导入人)
            weekDateList.forEach(date -> planQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getPlanQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            salesPlanOtherInfo.setPlanQtyLabel(SalesPlanOtherEnum.PLAN_QTY.getDesc());
            salesPlanOtherInfo.setPlanQtys(planQtys);
            if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                //设置上次确认量(全渠道)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getAllchannelLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(全渠道)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getAllchannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                // 设置下级确认量(全渠道)
                weekDateList.forEach(date -> subordinateConfirms.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                salesPlanOtherInfo.setSubordinateConfirmedQtyLabel(SalesPlanOtherEnum.SUBORDINATE_CONFIRMED_QTY.getDesc());
                salesPlanOtherInfo.setSubordinateConfirmedQtys(subordinateConfirms);
            } else {
                //设置上次确认量(渠道)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(渠道)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置上次确认量(导入)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(导入人)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            }
            salesPlanOtherInfo.setLastConfirmedQtyLabel(SalesPlanOtherEnum.LAST_CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setLastConfirmedQtys(lastConfirmedQtys);
            salesPlanOtherInfo.setConfirmedQtyLabel(SalesPlanOtherEnum.CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setConfirmedQtys(confirmedQtys);
            salesPlanOtherInfo.setPlanDifferenceLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_DIFFERIN.getDesc());
            salesPlanOtherInfo.setPlanProportionLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_PROPORTION.getDesc());
            // 计划与确认差值:确认量（渠道）-计划量（渠道）
            for (int i = 0; i < weekDateList.size(); i++) {
                planDifferences.add(confirmedQtys.get(i).subtract(planQtys.get(i)).
                        compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : confirmedQtys.get(i).subtract(planQtys.get(i)));
            }
            // 计划与确认比例:(（确认量（渠道）- 计划量（渠道））/确认量（渠道）
            for (int i = 0; i < weekDateList.size(); i++) {
                planProportions.add(confirmedQtys.get(i).compareTo(BigDecimal.ZERO) == 0
                        || confirmedQtys.get(i).subtract(planQtys.get(i)).compareTo(BigDecimal.ZERO) == 0 ?
                        BigDecimal.ZERO : (confirmedQtys.get(i).subtract(planQtys.get(i))).divide(confirmedQtys.get(i), 7, BigDecimal.ROUND_HALF_UP));
            }
            salesPlanOtherInfo.setPlanDifferences(planDifferences);
            salesPlanOtherInfo.setPlanProportions(planProportions);
            */
/*List<List<Long>> idList = new ArrayList<>();
            weekDateList.forEach(date -> idList.add(paramMap.get(key).stream()
                    .filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 &&
                            item.getPlanEndDate().compareTo(date.get("endTime")) == 0)
                    .map(SalesPlanOtherDTO::getId).collect(Collectors.toList())));
            salesPlanOtherInfo.setIds(idList);
            if (ObjectUtil.isNotNull(paramMap.get(key).get(0).getType())) {
                List<Integer> conStatus = new ArrayList<>();
                List<Integer> chconStatus = new ArrayList<>();
                List<Integer> allchconStatus = new ArrayList<>();
                List<String> types = new ArrayList<>();
                List<Integer> statuss = new ArrayList<>();
                weekDateList.forEach(date -> {
                    List<Integer> stas = paramMap.get(key).stream().
                            filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0
                                    && item.getPlanEndDate().compareTo(date.get("endTime")) == 0)
                            .map(SalesPlanOtherDTO::getConfirmedStatus)
                            .distinct().collect(Collectors.toList());
                    if (stas.size() == 0) {
                        //1表示不能修改，0可以修改
                        Integer st = 1;
                        stas = new ArrayList<>();
                        stas.add(st);
                    }
                    conStatus.addAll(stas);
                });
                weekDateList.forEach(date -> {
                    List<Integer> chastas = paramMap.get(key).stream()
                            .filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0
                                    && item.getPlanEndDate().compareTo(date.get("endTime")) == 0)
                            .map(SalesPlanOtherDTO::getChannelConfirmedStatus)
                            .distinct().collect(Collectors.toList());
                    if (chastas.size() == 0) {
                        //1表示不能修改，0可以修改
                        Integer st = 1;
                        chastas = new ArrayList<>();
                        chastas.add(st);
                    }
                    chconStatus.addAll(chastas);
                });
                weekDateList.forEach(date -> {
                    List<Integer> allstas = paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0
                            && item.getPlanEndDate().compareTo(date.get("endTime")) == 0)
                            .map(SalesPlanOtherDTO::getAllchannelConfirmedStatus)
                            .distinct().collect(Collectors.toList());
                    if (allstas.size() == 0) {
                        //1表示不能修改，0可以修改
                        Integer st = 1;
                        allstas = new ArrayList<>();
                        allstas.add(st);
                    }
                    allchconStatus.addAll(allstas);
                });
                weekDateList.forEach(date -> {
                    List<String> type = paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0
                            && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getType)
                            .distinct().collect(Collectors.toList());
                    if (type.size() == 0) {
                        //15表示不能修改
                        String st = "15";
                        type = new ArrayList<>();
                        type.add(st);
                    }
                    types.addAll(type);
                });
                weekDateList.forEach(date -> {
                    List<Integer> sta = paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0
                            && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getStatus)
                            .distinct().collect(Collectors.toList());
                    if (sta.size() == 0) {
                        //1表示不能修改，2可以修改
                        Integer st = 1;
                        sta = new ArrayList<>();
                        sta.add(st);
                    }
                    statuss.addAll(sta);
                });
                salesPlanOtherInfo.setConfirmedStatusList(conStatus);
                salesPlanOtherInfo.setChannelConfirmedStatusList(chconStatus);
                salesPlanOtherInfo.setAllchannelConfirmedStatusList(allchconStatus);
                salesPlanOtherInfo.setTypeList(types);
                salesPlanOtherInfo.setStatusList(statuss);
            }*//*

            salesPlanOtherInfo.setLevel(level);
            //salesPlanOtherInfo.setOtherTypeList(typeList);
            //salesPlanOtherInfo.setOtherImpTypeList(typeImpList);
            salesPlanOtherInfo.setType(paramMap.get(key).get(0).getType());
            //获取渠道、区域、商品信息
            this.getInfoData(paramMap.get(key), salesPlanOtherInfo, salesPlanOther.getSkuCodeList());
            salesPlanOtherInfoList.add(salesPlanOtherInfo);
        });
        return salesPlanOtherInfoList;
    }

    */
/**
     * 获取渠道、区域、商品信息
     *
     * @param salesPlanOthers
     * @param salesPlanOtherInfo
     * @param skuCodeList
     * @return
     *//*

    private SalesPlanOtherInfoDTO getInfoData(List<SalesPlanOtherDTO> salesPlanOthers, SalesPlanOtherInfoDTO salesPlanOtherInfo, List<String> skuCodeList) {
        // 区域信息
        salesPlanOtherInfo.setArea(
                salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getProvinceName())).map(SalesPlanOtherDTO::getProvinceName).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getCityName())).map(e -> "/" + e.getCityName()).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getCountyName())).map(e -> "/" + e.getCountyName()).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getStoreName())).map(e -> "/" + e.getStoreName()).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getStoreName())).map(e -> "/" + e.getStoreCode()).distinct().collect(Collectors.joining()));


        // 渠道信息
        salesPlanOtherInfo.setChannel(
                salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getChannelName())).map(SalesPlanOtherDTO::getChannelName).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getSubChannelName())).map(e -> "/" + e.getSubChannelName()).distinct().collect(Collectors.joining()));
        // 品类信息
        salesPlanOtherInfo.setCategory(
                salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getPriCategoryName())).map(SalesPlanOtherDTO::getPriCategoryName).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getSecCategoryName())).map(e -> "/" + e.getSecCategoryName()).distinct().collect(Collectors.joining()) +
                        salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getTerCategoryName())).map(e -> "/" + e.getTerCategoryName()).distinct().collect(Collectors.joining()));
        //sku信息
        if (CollectionUtils.isNotEmpty(skuCodeList)) {
            salesPlanOtherInfo.setSkuName(salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getSkuCode())).map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.joining()) +
                    salesPlanOthers.stream().filter(item -> ObjectUtil.isNotNull(item.getSkuName())).map(e -> "/" + e.getSkuName()).distinct().collect(Collectors.joining()));
        }
        //一级渠道
        salesPlanOtherInfo.setChannelCode(salesPlanOthers.get(0).getChannelCode());
        salesPlanOtherInfo.setSubChannelCode(salesPlanOthers.get(0).getSubChannelCode());
        salesPlanOtherInfo.setPriCategoryCode(salesPlanOthers.get(0).getPriCategoryCode());
        salesPlanOtherInfo.setSecCategoryCode(salesPlanOthers.get(0).getSecCategoryCode());
        salesPlanOtherInfo.setTerCategoryCode(salesPlanOthers.get(0).getSecCategoryCode());
        salesPlanOtherInfo.setStoreCode(salesPlanOthers.get(0).getStoreCode());
        salesPlanOtherInfo.setProvinceCode(salesPlanOthers.get(0).getProvinceCode());
        salesPlanOtherInfo.setCityCode(salesPlanOthers.get(0).getCityCode());
        salesPlanOtherInfo.setCountyCode(salesPlanOthers.get(0).getCountyCode());
        salesPlanOtherInfo.setType(SalesOtherTypeEnum.getNameByType(salesPlanOthers.get(0).getType()));
        return salesPlanOtherInfo;
    }


    */
/**
     * 处理查询出来的条数和数据
     *//*

    */
/*public SalesPlanOtherDO dealData(List<SalesPlanOtherDO> list, SalesPlanOtherDTO salesPlanOther) {
        //处理查询出来的数据
        //把查询的结果代入新的对象中，用于查询数据
        SalesPlanOtherDO salesPlanOtherDO = new SalesPlanOtherDO();
        if (ObjectUtil.isNotEmpty(list)) {
            salesPlanOtherDO.setChannelCode(list.get(0).getChannelCode());
            salesPlanOtherDO.setSubChannelCode(list.get(0).getSubChannelCode());
            salesPlanOtherDO.setProvinceCode(list.get(0).getProvinceCode());
            salesPlanOtherDO.setCityCode(list.get(0).getCityCode());
            salesPlanOtherDO.setCountyCode(list.get(0).getCountyCode());
            salesPlanOtherDO.setStoreCode(list.get(0).getStoreCode());
            salesPlanOtherDO.setPriCategoryCode(list.get(0).getPriCategoryCode());
            salesPlanOtherDO.setSecCategoryCode(list.get(0).getSecCategoryCode());
            salesPlanOtherDO.setTerCategoryCode(list.get(0).getTerCategoryCode());
            salesPlanOtherDO.setSkuCode(list.get(0).getSkuCode());
            salesPlanOtherDO.setType(list.get(0).getType());
            salesPlanOtherDO.setSalesPlanOtherList(list);
        }
        salesPlanOtherDO.setStartTime(salesPlanOther.getStartTime());
        salesPlanOtherDO.setEndTime(salesPlanOther.getEndTime());
        return salesPlanOtherDO;
    }*//*


    */
/**
     *
     * @param list
     * @param salesPlanOther
     * @return
     *//*

    */
/*public SalesPlanOtherDTO dealDataSelect(List<SalesPlanOtherDTO> list, SalesPlanOtherDTO salesPlanOther) {
        //处理查询出来的数据
        if (ObjectUtil.isNotEmpty(list)) {
            salesPlanOther.setId(list.get(0).getId());
            salesPlanOther.setChannelCode(list.get(0).getChannelCode());
            salesPlanOther.setSubChannelCode(list.get(0).getSubChannelCode());
            salesPlanOther.setProvinceCode(list.get(0).getProvinceCode());
            salesPlanOther.setCityCode(list.get(0).getCityCode());
            salesPlanOther.setCountyCode(list.get(0).getCountyCode());
            salesPlanOther.setStoreCode(list.get(0).getStoreCode());
            salesPlanOther.setPriCategoryCode(list.get(0).getPriCategoryCode());
            salesPlanOther.setSecCategoryCode(list.get(0).getSecCategoryCode());
            salesPlanOther.setTerCategoryCode(list.get(0).getTerCategoryCode());
            salesPlanOther.setSkuCode(list.get(0).getSkuCode());
            salesPlanOther.setType(list.get(0).getType());
            salesPlanOther.setSalesPlanOtherList(list);
        }
        return salesPlanOther;
    }*//*


    */
/**
     * 获取系统重复数据
     *
     * @param list
     * @return
     *//*

    public List<SalesPlanOtherDTO> dealData(List<SalesPlanOtherDTO> list, Date start, Date end) {
        //开始时间
        Date startDate;
        //结束时间
        Date endDate;
        //计划导入
        if (start == null && end == null) {
            //获取当前周第二周到后五周的日期
            List<Map<String, Date>> lastDateMap = MyDateUtil.getWeekDates(new Date(), CommonConstants.SIX);
            startDate = lastDateMap.get(1).get("startTime");
            endDate = lastDateMap.get(5).get("startTime");
        } else {
            //营销同步
            startDate = start;
            endDate = end;
        }
        List<SalesPlanOtherDTO> dtoList = new ArrayList<>();
        //处理查询出来的数据
        //把查询的结果代入新的对象中，用于查询数据
        if (ObjectUtil.isNotEmpty(list)) {
            Map<String, List<SalesPlanOtherDTO>> mapList = list.stream().collect(Collectors.groupingBy(o -> (o.getChannelCode() + o.getType() + o.getSkuCode() + (ObjectUtil.isNotNull(o.getStoreCode()) ? o.getStoreCode() : "") + (ObjectUtil.isNotNull(o.getProvinceCode()) ? o.getProvinceCode() : "") + (ObjectUtil.isNotNull(o.getCityCode()) ? o.getCityCode() : "") + (ObjectUtil.isNotNull(o.getCountyCode()) ? o.getCountyCode() : ""))));
            List<SalesPlanOtherDTO> proList = new ArrayList<>();
            List<SalesPlanOtherDTO> cityList = new ArrayList<>();
            List<SalesPlanOtherDTO> storeList = new ArrayList<>();
            mapList.forEach((k, v) -> {
                SalesPlanOtherDTO otherDto = new SalesPlanOtherDTO();
                //如果市和门店都是空，区域只填了省
                if (StringUtils.isEmpty(v.get(0).getCityCode()) && StringUtils.isEmpty(v.get(0).getStoreCode())) {
                    proList.add(v.get(0));
                }
                //如果市不是空门店是空，区域只填了省、市
                if (!StringUtils.isEmpty(v.get(0).getCityCode()) && StringUtils.isEmpty(v.get(0).getStoreCode())) {
                    cityList.add(v.get(0));
                }
                //如果门店不是空，区域填了门店
                if (!StringUtils.isEmpty(v.get(0).getStoreCode())) {
                    storeList.add(v.get(0));
                }
            });
            if (proList.size() > 0) {
                SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                dto.setPlanStartDate(startDate);
                dto.setPlanEndDate(endDate);
                dto.setSalesPlanOtherList(proList);
                dtoList.addAll(salesPlanOtherRespository.getRepeatPro(dto));
            }
            if (cityList.size() > 0) {
                SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                dto.setPlanStartDate(startDate);
                dto.setPlanEndDate(endDate);
                dto.setSalesPlanOtherList(cityList);
                dtoList.addAll(salesPlanOtherRespository.getRepeatCity(dto));
            }
            if (storeList.size() > 0) {
                SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                dto.setPlanStartDate(startDate);
                dto.setPlanEndDate(endDate);
                dto.setSalesPlanOtherList(storeList);
                dtoList.addAll(salesPlanOtherRespository.getRepeatStore(dto));
            }

        }
        return dtoList;
    }


    */
/**
     * Excel中的每条数据
     *
     * @param paramMap
     * @param salesPlanOther
     * @param targets
     * @param dateTitles
     * @return
     *//*

    private List<List<Object>> getExcelTargetList(Map<String, List<SalesPlanOtherDTO>> paramMap, SalesPlanOtherDTO salesPlanOther, List<String> targets, List<String> dateTitles, Integer level) {
        List<SalesPlanOtherInfoDTO> salesPlanOtherInfoList = new ArrayList<>();
        List<Map<String, Date>> weekDateList = salesPlanOther.getWeekDateList();
        List<List<Object>> exportDataList = new ArrayList<>();
        //将分组后的数据汇总
        paramMap.keySet().forEach(key -> {
            //上次计划量
            List<BigDecimal> lastPlanQtys = new ArrayList<>();
            //上次确认量
            List<BigDecimal> lastConfirmedQtys = new ArrayList<>();
            //计划量
            List<BigDecimal> planQtys = new ArrayList<>();
            //确认量
            List<BigDecimal> confirmedQtys = new ArrayList<>();
            //下级确认量
            List<BigDecimal> subordinateConfirms = new ArrayList<>();
            //计划差异
            List<BigDecimal> planDifferences = new ArrayList<>();
            //计划比例
            List<BigDecimal> planProportions = new ArrayList<>();

            //渠道确认量
            List<BigDecimal> channelConfirmedQtys = new ArrayList<>();
            //全渠道确认量
            List<BigDecimal> allchannelConfirmedQtys = new ArrayList<>();
            //渠道上次确认量
            List<BigDecimal> channelLastConfirmedQtys = new ArrayList<>();
            //全渠道上次确认量
            List<BigDecimal> allchannelLastConfirmedQtys = new ArrayList<>();

            SalesPlanOtherInfoDTO salesPlanOtherInfo = new SalesPlanOtherInfoDTO();

            // 设置上次计划量
            weekDateList.forEach(date -> lastPlanQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getLastPlanQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            salesPlanOtherInfo.setLastPlanQtyLabel(SalesPlanOtherEnum.LAST_PLAN_QTY.getDesc());
            salesPlanOtherInfo.setLastPlanQtys(lastPlanQtys);

            // 设置计划量(导入人)
            weekDateList.forEach(date -> planQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getPlanQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            salesPlanOtherInfo.setPlanQtyLabel(SalesPlanOtherEnum.PLAN_QTY.getDesc());
            salesPlanOtherInfo.setPlanQtys(planQtys);

            if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                //设置上次确认量(全渠道)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getAllchannelLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(全渠道)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getAllchannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));

                // 设置下级确认量(全渠道)
                weekDateList.forEach(date -> subordinateConfirms.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                salesPlanOtherInfo.setSubordinateConfirmedQtyLabel(SalesPlanOtherEnum.SUBORDINATE_CONFIRMED_QTY.getDesc());
                salesPlanOtherInfo.setSubordinateConfirmedQtys(subordinateConfirms);
            } else  {
                //设置上次确认量(渠道)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(渠道)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getChannelConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置上次确认量(导入)
                weekDateList.forEach(date -> lastConfirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getLastConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
                //设置确认量(导入人)
                weekDateList.forEach(date -> confirmedQtys.add(paramMap.get(key).stream().filter(item -> item.getPlanStartDate().compareTo(date.get("startTime")) == 0 && item.getPlanEndDate().compareTo(date.get("endTime")) == 0).map(SalesPlanOtherDTO::getConfirmedQty).reduce(BigDecimal.ZERO, BigDecimal::add)));
            }

            salesPlanOtherInfo.setLastConfirmedQtyLabel(SalesPlanOtherEnum.LAST_CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setLastConfirmedQtys(lastConfirmedQtys);

            salesPlanOtherInfo.setConfirmedQtyLabel(SalesPlanOtherEnum.CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setConfirmedQtys(confirmedQtys);
            salesPlanOtherInfo.setPlanDifferenceLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_DIFFERIN.getDesc());
            salesPlanOtherInfo.setPlanProportionLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_PROPORTION.getDesc());
            // 计划与确认差值:确认量（渠道）-计划量（渠道）
            for (int i = 0; i < weekDateList.size(); i++) {
                planDifferences.add(confirmedQtys.get(i).subtract(planQtys.get(i)).
                        compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : confirmedQtys.get(i).subtract(planQtys.get(i)));
            }
            // 计划与确认比例:(（确认量（渠道）- 计划量（渠道））/确认量（渠道）
            for (int i = 0; i < weekDateList.size(); i++) {
                planProportions.add(confirmedQtys.get(i).compareTo(BigDecimal.ZERO) == 0
                        || confirmedQtys.get(i).subtract(planQtys.get(i)).compareTo(BigDecimal.ZERO) == 0 ?
                        BigDecimal.ZERO : (confirmedQtys.get(i).subtract(planQtys.get(i))).divide(confirmedQtys.get(i), 7, BigDecimal.ROUND_HALF_UP));
            }
            salesPlanOtherInfo.setPlanDifferences(planDifferences);
            salesPlanOtherInfo.setPlanProportions(planProportions);
            //获取渠道、区域、商品信息
            this.getInfoData(paramMap.get(key), salesPlanOtherInfo, salesPlanOther.getSkuCodeList());
            for (int i = 0; i < targets.size(); i++) {
                List<Object> itemRow = new ArrayList<>();
                //加入渠道，区域，品类，商品  信息
                this.setExcelRowAdvancedSearchCondition(salesPlanOtherInfo, itemRow);
                //加入指标
                itemRow.add(targets.get(i));
                //导入人没有下级确认量
                if (targets.size() == 6) {
                    //加入数据
                    for (int j = 0; j < (dateTitles.size() - 1); j++) {
                        //获取指标集合，这里没有排序，默认使用枚举的顺序
                        switch (i) {
                            case 0:
                                itemRow.add(lastPlanQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : lastPlanQtys.get(j));
                                break;
                            case 1:
                                itemRow.add(lastConfirmedQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : lastConfirmedQtys.get(j));
                                break;
                            case 2:
                                itemRow.add(planQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : planQtys.get(j));
                                break;
                            case 3:
                                itemRow.add(confirmedQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : confirmedQtys.get(j));
                                break;
                            case 4:
                                itemRow.add(planDifferences.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : planDifferences.get(j));
                                break;
                            case 5:
                                itemRow.add(planProportions.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : (planProportions.get(j).multiply(new BigDecimal(100)).setScale(3, BigDecimal.ROUND_HALF_UP)) + "%");
                                break;
                            default:
                                break;
                        }
                    }
                } else {
                    //加入数据
                    for (int j = 0; j < (dateTitles.size() - 1); j++) {
                        //获取指标集合，这里没有排序，默认使用枚举的顺序
                        switch (i) {
                            case 0:
                                itemRow.add(lastPlanQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : lastPlanQtys.get(j));
                                break;
                            case 1:
                                itemRow.add(lastConfirmedQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : lastConfirmedQtys.get(j));
                                break;
                            case 2:
                                itemRow.add(planQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : planQtys.get(j));
                                break;
                            case 3:
                                itemRow.add(subordinateConfirms.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : subordinateConfirms.get(j));
                                break;
                            case 4:
                                itemRow.add(confirmedQtys.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : confirmedQtys.get(j));
                                break;
                            case 5:
                                itemRow.add(planDifferences.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : planDifferences.get(j));
                                break;
                            case 6:
                                itemRow.add(planProportions.get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : (planProportions.get(j).multiply(new BigDecimal(100)).setScale(3, BigDecimal.ROUND_HALF_UP)) + "%");
                                break;
                            default:
                                break;
                        }
                    }
                }
                //合计
                BigDecimal total = BigDecimal.ZERO;
                String percentage = "";
                //获取除日期外的下标
                int index = itemRow.size() - (dateTitles.size() - 1);
                List<Object> numRow = new ArrayList<>();
                numRow.addAll(itemRow);
                for (int a = 0; a < index; a++) {
                    numRow.remove(numRow.get(0));
                }
                //循环增加查询的日期对应指标数量
                for (Object obj : numRow) {
                    BigDecimal num = BigDecimal.ZERO;
                    if ("-".equals(obj)) {
                        num = BigDecimal.ZERO;
                        total = total.add(num);
                    } else {
                        if (obj.toString().contains("%")) {
                            String nums = obj.toString().substring(0, obj.toString().length() - 1);
                            num = new BigDecimal(nums);
                            total = total.add(num);
                            percentage = total + "%";
                        } else {
                            num = new BigDecimal(obj.toString());
                            total = total.add(num);
                        }
                    }
                }
                if ("".equals(percentage)) {
                    itemRow.add(total.equals(BigDecimal.ZERO) ? "-" : total);
                } else {
                    itemRow.add(percentage);
                }
                exportDataList.add(itemRow);
            }
        });
        return exportDataList;
    }

    */
/**
     * excel每行数据设置 高级搜索  信息
     *
     * @param salesPlanOtherInfo
     * @param itemRow
     * @return void
     **//*

    private void setExcelRowAdvancedSearchCondition(SalesPlanOtherInfoDTO salesPlanOtherInfo, List<Object> itemRow) {
        if (!StringUtils.isEmpty(salesPlanOtherInfo.getChannel())) {
            itemRow.add(salesPlanOtherInfo.getChannel());
        }
        if (!StringUtils.isEmpty(salesPlanOtherInfo.getType())) {
            itemRow.add(salesPlanOtherInfo.getType());
        }
        if (!StringUtils.isEmpty(salesPlanOtherInfo.getArea())) {
            itemRow.add(salesPlanOtherInfo.getArea());
        }
        if (!StringUtils.isEmpty(salesPlanOtherInfo.getCategory())) {
            itemRow.add(salesPlanOtherInfo.getCategory());
        }
        if (!StringUtils.isEmpty(salesPlanOtherInfo.getSkuName())) {
            itemRow.add(salesPlanOtherInfo.getSkuName());
        }
    }

    */
/**
     * 获取分组条件
     *
     * @param salesPlanOtherDTO
     * @return
     *//*

    public List<String> getConditions(SalesPlanOtherDTO salesPlanOtherDTO) {
        List<String> conditions = new ArrayList<>();
        if (CollectionUtils.isEmpty(salesPlanOtherDTO.getChannelCodeList())) {
            conditions.add(BaseSearchColumnEnum.CHANNEL_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getChannelCodeList())) {
            conditions.add(BaseSearchColumnEnum.SUB_CHANNEL_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getTypeList())) {
            conditions.add(BaseSearchColumnEnum.TYPE_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getProvinceCodeList())) {
            conditions.add(BaseSearchColumnEnum.PROVINCE_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getCityCodeList())) {
            conditions.add(BaseSearchColumnEnum.CITY_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getCountyCodeList())) {
            conditions.add(BaseSearchColumnEnum.COUNTY_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getStoreCodeList())) {
            conditions.add(BaseSearchColumnEnum.STORE_CODE.getColumn());
            conditions.add(BaseSearchColumnEnum.LATEST_ARRIVAL_DATE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getPriCategoryCodeList())) {
            conditions.add(BaseSearchColumnEnum.PRI_CATEGORY_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getSecCategoryCodeList())) {
            conditions.add(BaseSearchColumnEnum.SEC_CATEGORY_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getTerCategoryCodeList())) {
            conditions.add(BaseSearchColumnEnum.TER_CATEGORY_CODE.getColumn());
        }
        if (CollectionUtils.isNotEmpty(salesPlanOtherDTO.getSkuCodeList())) {
            conditions.add(BaseSearchColumnEnum.SKU_CODE.getColumn());
            conditions.add(BaseSearchColumnEnum.TER_CATEGORY_CODE.getColumn());
        }
        return conditions;
    }

    private int setExcelTitles(List<List<String>> heads, List<String> dateTitles) {
        //获取高级搜索标题
        this.getExcelAdvancedSearchTitle(heads);
        int result = heads.size();
        //加入指标标题
        List<String> targetTitle = new ArrayList<>();
        targetTitle.add(ExcelExportTitleEnum.TARGET_TITLE.getTitle());
        heads.add(targetTitle);
        //加入日期标题
        AdvancedSearchUtil.getExcelDateTitle(heads, dateTitles);
        return result;
    }
    */
/*private int setExcelTitles(List<List<String>> heads, List<String> conditions, List<String> dateTitles) {
        //获取高级搜索标题
        this.getExcelAdvancedSearchTitle(heads, conditions);
        int result = heads.size();
        //加入指标标题
        List<String> targetTitle = new ArrayList<>();
        targetTitle.add(ExcelExportTitleEnum.TARGET_TITLE.getTitle());
        heads.add(targetTitle);
        //加入日期标题
        AdvancedSearchUtil.getExcelDateTitle(heads, dateTitles);
        return result;
    }*//*


    private void setExcelTitle(List<List<String>> heads, String type, List<String> dateTitles) {
        //获取高级搜索标题
        this.getExcelAdvancedSearchTitle(heads, type);
        //加入日期标题
        AdvancedSearchUtil.getExcelDateTitle(heads, dateTitles);
    }

    */
/**
     * Excel表头
     *
     * @param heads
     *//*

    */
/*private void getExcelAdvancedSearchTitle(List<List<String>> heads, List<String> conditions) {
        if (conditions.contains(BaseSearchColumnEnum.CHANNEL_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.CHANNEL_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.TYPE_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.PLAN_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.SUB_CHANNEL_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.CHANNEL_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.PROVINCE_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.AREA_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.CITY_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.AREA_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.COUNTY_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.AREA_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.STORE_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.AREA_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.PRI_CATEGORY_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.CATEGORY_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.SEC_CATEGORY_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.CATEGORY_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.TER_CATEGORY_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.CATEGORY_TITLE.getTitle());
        }
        if (conditions.contains(BaseSearchColumnEnum.SKU_CODE.getColumn())) {
            setList(heads, ExcelExportTitleEnum.SKU_TITLE.getTitle());
        }
    }*//*

    private void getExcelAdvancedSearchTitle(List<List<String>> heads) {
        setList(heads, ExcelExportTitleEnum.CHANNEL_TITLE.getTitle());
        setList(heads, ExcelExportTitleEnum.PLAN_TITLE.getTitle());
        setList(heads, ExcelExportTitleEnum.AREA_TITLE.getTitle());
        setList(heads, ExcelExportTitleEnum.STORE_TITLE.getTitle());
        setList(heads, ExcelExportTitleEnum.CATEGORY_TITLE.getTitle());
        setList(heads, ExcelExportTitleEnum.SKU_TITLE.getTitle());
    }


    private void getExcelAdvancedSearchTitle(List<List<String>> heads, String type) {
        setList(heads, ExportTemplateTitleEnum.CHANNEL_CODE_TITLE.getTitle());
        setList(heads, ExportTemplateTitleEnum.CHANNEL_NAME_TITLE.getTitle());
        setList(heads, ExportTemplateTitleEnum.PROVINCE_TITLE.getTitle());
        setList(heads, ExportTemplateTitleEnum.CITY_TITLE.getTitle());
        //新品、销售计划（直营、加盟有门店）
        if (SalesPlanTypeEnum.PLAN_ELEVEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SIXTEEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SEVENTEEN.getType().equals(type)) {
            setList(heads, ExportTemplateTitleEnum.STORE_TITLE.getTitle());
        }
        setList(heads, ExportTemplateTitleEnum.SKU_CODE_TITLE.getTitle());
        setList(heads, ExportTemplateTitleEnum.SKU_NAME_TITLE.getTitle());
        setList(heads, ExportTemplateTitleEnum.UNIT_TITLE.getTitle());
    }

    */
/**
     * 获取标题行list
     *
     * @param heads
     * @param title
     *//*

    private static void setList(List<List<String>> heads, String title) {
        List<String> list = new ArrayList<>();
        list.add(title);
        heads.add(list);
    }


    private List<SalesPlanOtherDTO> getSaleList(List<SalesPlanOtherSimpleDTO> simpleList, List<SkuInfosDTO> skus, List<CategorySimpleDTO> categorys, List<AreaDTO> provinceList,
                                                List<AreaDTO> cityNameList,
                                                List<StoreDTO> storeList, List<AreaDTO> provinceListByStore, List<AreaDTO> cityListByStore,
                                                List<AreaDTO> countyListByStore, List<AreaDTO> provinceNameListByCity,
                                                List<SkuUnitExtDTO> skuUnitList) {

        List<SalesPlanOtherDTO> dtoList = new ArrayList<>();
        for (SalesPlanOtherSimpleDTO simpleDto : simpleList) {
            for (OtherSimpleDTO otherDto : simpleDto.getList()) {
                SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
                dto.setSalesPlanActivityNo(simpleDto.getSalesPlanActivityNo());
                dto.setStatus(SalesConfirmStatusEnum.CONFIRMED.getType());
                dto.setSkuTypeCode(simpleDto.getSkuTypeCode());
                dto.setConfirmedQty(otherDto.getConfirmedQty());
                dto.setChannelConfirmedQty(otherDto.getConfirmedQty());
                dto.setAllchannelConfirmedQty(otherDto.getConfirmedQty());
                dto.setPlanStartDate(DateUtil.parseDate(otherDto.getPlanWeek().split("-")[0]));
                dto.setPlanEndDate(DateUtil.parseDate(otherDto.getPlanWeek().split("-")[1]));
                dto.setCreator(1L);
                dto.setCreatorName("营销中心导入");
                dto.setModifier(1L);
                dto.setModifierName("营销中心导入");
                String type;
                String channelName;
                if (ChannelTypeEnum.DIRECTLY_OPERATE.getCode().equals(simpleDto.getChannelCode())) {
                    type = SalesOtherTypeEnum.PLAN_ONE.getType();
                    channelName = ChannelTypeEnum.DIRECTLY_OPERATE.getDesc();
                } else if (ChannelTypeEnum.JOIN_IN.getCode().equals(simpleDto.getChannelCode())) {
                    type = SalesOtherTypeEnum.PLAN_TWO.getType();
                    channelName = ChannelTypeEnum.JOIN_IN.getDesc();
                } else if (ChannelTypeEnum.CLOUD_BUSINESS.getCode().equals(simpleDto.getChannelCode())) {
                    type = SalesOtherTypeEnum.PLAN_THREE.getType();
                    channelName = ChannelTypeEnum.CLOUD_BUSINESS.getDesc();
                } else {
                    type = SalesOtherTypeEnum.PLAN_FOUR.getType();
                    channelName = ChannelTypeEnum.APP.getDesc();
                }
                dto.setType(type);
                dto.setChannelCode(simpleDto.getChannelCode());
                dto.setChannelName(channelName);
                if (ObjectUtil.isNotNull(simpleDto.getStoreCode())) {
                    List<StoreDTO> stores = storeList.stream().filter(store -> store.getCode().equals(simpleDto.getStoreCode())).collect(Collectors.toList());
                    //如果填了门店
                    if (stores.size() > 0) {
                        dto.setStoreCode(stores.get(0).getCode());
                        dto.setStoreName(stores.get(0).getName());
                        if (provinceListByStore.size() > 0) {
                            dto.setProvinceCode(provinceListByStore.get(0).getCode());
                            dto.setProvinceName(provinceListByStore.get(0).getName());
                        }
                        if (cityListByStore.size() > 0) {
                            dto.setCityCode(cityListByStore.get(0).getCode());
                            dto.setCityName(cityListByStore.get(0).getName());
                        }
                        if (countyListByStore.size() > 0) {
                            dto.setCountyCode(countyListByStore.get(0).getCode());
                            dto.setCountyName(countyListByStore.get(0).getName());
                        }
                    }
                }
                //如果填了城市
                List<AreaDTO> city = cityNameList.stream().filter(pro -> ObjectUtil.isNotNull(simpleDto.getCityName()) && pro.getName().contains(simpleDto.getCityName())).collect(Collectors.toList());
                if (city.size() > 0) {
                    if (provinceNameListByCity.size() > 0) {
                        List<AreaDTO> province = provinceNameListByCity.stream().filter(pro -> pro.getName().contains(simpleDto.getProvinceName())).collect(Collectors.toList());
                        if (province.size() > 0) {
                            dto.setProvinceCode(province.get(0).getCode());
                            dto.setProvinceName(province.get(0).getName());
                        }
                    }
                    dto.setCityCode(city.get(0).getCode());
                    dto.setCityName(city.get(0).getName());
                } else {
                    //省份必填(填了城市取城市)
                    List<AreaDTO> province = provinceList.stream().filter(pro -> pro.getName().contains(simpleDto.getProvinceName())).collect(Collectors.toList());
                    if (province.size() > 0) {
                        dto.setProvinceCode(province.get(0).getCode());
                        dto.setProvinceName(province.get(0).getName());
                    }
                }
                //获取商品信息
                List<SkuInfosDTO> skuInfo = skus.stream().filter(sku -> sku.getSkuCode().equals(simpleDto.getSkuCode())).collect(Collectors.toList());
                if (skuInfo.size() > 0) {
                    List<CategorySimpleDTO> category = categorys.stream().filter(ter -> ter.getId().equals(skuInfo.get(0).getCategoryId())).collect(Collectors.toList());
                    if (category.size() > 0) {
                        category.get(0).getParentCategoryDTOList().forEach(cate -> {
                            if (cate.getCategoryLevel().equals(CommonConstants.CATEGORY_LEVEL_ONE)) {
                                dto.setPriCategoryCode(cate.getCategoryCode().toString());
                                dto.setPriCategoryName(cate.getCategoryName());
                            } else if (cate.getCategoryLevel().equals(CommonConstants.CATEGORY_LEVEL_TWO)) {
                                dto.setSecCategoryCode(cate.getCategoryCode().toString());
                                dto.setSecCategoryName(cate.getCategoryName());
                            } else if (cate.getCategoryLevel().equals(CommonConstants.CATEGORY_LEVEL_THREE)) {
                                dto.setTerCategoryCode(cate.getCategoryCode().toString());
                                dto.setTerCategoryName(cate.getCategoryName());
                            }
                        });
                    }
                    List<SkuUnitExtDTO> units = skuUnitList.stream().filter(ter -> ter.getSkuCode().equals(skuInfo.get(0).getSkuCode())).collect(Collectors.toList());
                    if (units.size() > 0) {
                        dto.setUnitCode(units.get(0).getUnitCode());
                        dto.setUnitName(units.get(0).getUnitName());
                    }
                    dto.setSkuCode(skuInfo.get(0).getSkuCode());
                    dto.setSkuName(skuInfo.get(0).getSkuName());
                }
                dtoList.add(dto);
            }

        }
        return dtoList;
    }


    */
/**
     * 开启线程导入
     *
     * @param saleLists
     *//*

    public void startThread(List<SalesPlanOtherDTO> saleLists) {
        new Thread((new Runnable() {
            @Override
            public void run() {
                try {
                    // 批量同步数据
                    log.info("-------线程启动开始------");
                    int successNums = 0;
                    // 开始时间
                    long start = System.currentTimeMillis();
                    if (saleLists.size() < CommonConstants.PLAN_OTHER_INSERT_MAX) {
                        successNums = salesPlanOtherRespository.addPlanOtherData(saleLists);
                    } else {
                        //新增数量超过30000分批导入
                        //每条线程最小处理任务数
                        int perThreadHandleCount = CommonConstants.PLAN_OTHER_INSERT_MAX;
                        //线程池的最大线程数
                        int countNum = 0;
                        while (countNum < saleLists.size()) {
                            countNum += perThreadHandleCount;
                            List<SalesPlanOtherDTO> dtos = ImmutableList.copyOf(saleLists.subList(countNum - perThreadHandleCount,
                                    countNum < saleLists.size() ? countNum : saleLists.size()));
                            int size = salesPlanOtherRespository.addPlanOtherData(dtos);
                            successNums += size;
                        }
                    }
                    OperationLogRecordDTO operationDto = new OperationLogRecordDTO();
                    operationDto.setOpSign(saleLists.get(0).getOpSign());
                    operationDto.setModifier(saleLists.get(0).getModifier());
                    operationDto.setModifierName(saleLists.get(0).getModifierName());
                    //新增成功
                    if (successNums == saleLists.size()) {
                        operationDto.setOpTime((int) (System.currentTimeMillis() - start) + "ms");
                        operationDto.setOpStatus(OperationStatusEnum.SUCCESS.getType());
                    } else {
                        operationDto.setFailReason("导入失败");
                        operationDto.setOpStatus(OperationStatusEnum.FAIL.getType());
                    }
                    operationLogRecordRepository.updateOperationLogStatus(operationDto);
                    log.info("-------线程启动结束------");
                } catch (Exception ex) {
                    OperationLogRecordDTO operationDtoa = new OperationLogRecordDTO();
                    operationDtoa.setOpSign(saleLists.get(0).getOpSign());
                    operationDtoa.setFailReason(ex.toString());
                    operationDtoa.setModifier(saleLists.get(0).getModifier());
                    operationDtoa.setModifierName(saleLists.get(0).getModifierName());
                    operationDtoa.setOpStatus(OperationStatusEnum.FAIL.getType());
                    operationLogRecordRepository.updateOperationLogStatus(operationDtoa);
                    log.info("导入数据失败，" + ex);
                }
            }
        })).start();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean pushDataToTransaction() {
        //查询所有新品新店计划的数据
        List<SalesPlanOtherDTO> salesList = salesPlanOtherRespository.listBySalesOtherPlan();
        //新店加盟
        List<NewPlanDTO> newStoreJoin = new ArrayList<>();
        //新店直营
        List<NewPlanDTO> newStoreDirectly = new ArrayList<>();
        //新品直营
        List<NewPlanDTO> newProductsDirectly = new ArrayList<>();
        //新品加盟(暂时不推)
        //List<NewPlanDTO> newProductsJoin = new ArrayList<>();
        for (SalesPlanOtherDTO sales : salesList) {
            NewPlanDTO planDto = new NewPlanDTO();
            if (SalesOtherTypeEnum.PLAN_FIVE.getType().equals(sales.getType())) {
                planDto.setShopCode(sales.getStoreCode());
                planDto.setNewPresaleType(1);
                planDto.setSkuCode(sales.getSkuCode());
                planDto.setAssignSendTime(sales.getLatestArrivalDate());
                planDto.setSaleUnitCode(sales.getUnitCode());
                planDto.setSkuQuantity(sales.getConfirmedQty());
                newStoreJoin.add(planDto);
            } else if (SalesOtherTypeEnum.PLAN_SIX.getType().equals(sales.getType())) {
                planDto.setShopCode(sales.getStoreCode());
                planDto.setNewPresaleType(1);
                planDto.setSkuCode(sales.getSkuCode());
                planDto.setAssignSendTime(sales.getLatestArrivalDate());
                planDto.setSaleUnitCode(sales.getUnitCode());
                planDto.setSkuQuantity(sales.getConfirmedQty());
                newStoreDirectly.add(planDto);
            } else if (SalesOtherTypeEnum.PLAN_SEVEN.getType().equals(sales.getType())) {
                planDto.setShopCode(sales.getStoreCode());
                planDto.setNewPresaleType(2);
                planDto.setSkuCode(sales.getSkuCode());
                planDto.setAssignSendTime(sales.getLatestArrivalDate());
                planDto.setSaleUnitCode(sales.getUnitCode());
                planDto.setSkuQuantity(sales.getConfirmedQty());
                newProductsDirectly.add(planDto);
            } */
/*else {
                planDto.setShopCode(sales.getStoreCode());
                planDto.setNewPresaleType(2);
                planDto.setSkuCode(sales.getSkuCode());
                planDto.setAssignSendTime(sales.getLatestArrivalDate());
                planDto.setSaleUnitCode(sales.getUnitCode());
                planDto.setSkuQuantity(sales.getConfirmedQty());
                newProductsJoin.add(planDto);
            }*//*

        }

        if (newStoreJoin.size() > 0) {
            //按门店、要求到货时间分组
            Map<String, List<NewPlanDTO>> collect = newStoreJoin.stream().collect(Collectors.groupingBy(group -> group.getShopCode() + "--" + DateUtil.formatDate(group.getAssignSendTime()), Collectors.toList()));
            getGroupDatas(collect, 1);
        }
        if (newStoreDirectly.size() > 0) {
            //按门店、要求到货时间分组
            Map<String, List<NewPlanDTO>> collect = newStoreDirectly.stream().collect(Collectors.groupingBy(group -> group.getShopCode() + "--" + DateUtil.formatDate(group.getAssignSendTime()), Collectors.toList()));
            getGroupDatas(collect, 2);
        }
        if (newProductsDirectly.size() > 0) {
            //按门店、要求到货时间分组
            Map<String, List<NewPlanDTO>> collect = newProductsDirectly.stream().collect(Collectors.groupingBy(group -> group.getShopCode() + "--" + DateUtil.formatDate(group.getAssignSendTime()), Collectors.toList()));
            getGroupDatas(collect, 2);
        }
        */
/*if (newProductsJoin.size() > 0) {
            //按门店、要求到货时间分组
            Map<String, List<NewPlanDTO>> collect = newProductsJoin.stream().collect(Collectors.groupingBy(group -> group.getShopCode() + "--" + DateUtil.formatDate(group.getAssignSendTime()), Collectors.toList()));
            getGroupDatas(collect, 1);
        }*//*

        return true;
    }


    public void getGroupDatas(Map<String, List<NewPlanDTO>> collect, Integer type) {
        if (type == 1) {
            //循环调用交易中心接口，推送加盟数据
            collect.keySet().forEach(key -> {
                try {
                    Response<String> response = transactionFacade.importJoinList(collect.get(key));
                    if ("0".equals(response.getCode())) {
                        salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 1, collect.get(key).get(0).getNewPresaleType(), null);
                    } else {
                        salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 2, collect.get(key).get(0).getNewPresaleType(), response.getMsg().toString());
                        //处理失败
                    }
                } catch (Exception e) {
                    //处理失败
                    salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 2, collect.get(key).get(0).getNewPresaleType(), e.toString());
                    log.error(e.toString());
                }
            });
        } else {
            //循环调用交易中心接口，推送直营数据
            collect.keySet().forEach(key -> {
                try {
                    Response<String> response = transactionFacade.importDirectlyList(collect.get(key));
                    if ("0".equals(response.getCode())) {
                        salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 1, collect.get(key).get(0).getNewPresaleType(), null);
                    } else {
                        //处理失败
                        salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 2, collect.get(key).get(0).getNewPresaleType(), response.getMsg().toString());
                    }
                } catch (Exception e) {
                    salesPlanOtherRespository.updatePushStatus(key.split("--")[0], DateUtil.parseDate(key.split("--")[1]), 2, collect.get(key).get(0).getNewPresaleType(), e.toString());
                    //处理失败
                    log.error(e.toString());
                }
            });
        }
    }

    @Override
    public void delete(String opSign) {
        salesPlanOtherRespository.delete(opSign);
    }


    private List<SalesWriteDTO> getLastWeekByType(String type) {
        List<Map<String, Date>> lastDateMap = MyDateUtil.getWeekDatess(new Date(), CommonConstants.SIX);
        //上一次计划第一周（当前）时间
        Date startTimeOne = lastDateMap.get(0).get("startTime");
        //上一次计划第二周时间（对应当前周）
        Date startTimeTwo = lastDateMap.get(1).get("startTime");
        //上一次计划第三周时间
        Date startTimeThree = lastDateMap.get(2).get("startTime");
        //上一次计划第四周时间
        Date startTimeFour = lastDateMap.get(3).get("startTime");
        //上一次计划第五周时间
        Date startTimeFive = lastDateMap.get(4).get("startTime");
        //上一次计划第六周时间
        Date startTimeSix = lastDateMap.get(5).get("startTime");
        List<String> types = new ArrayList<>();
        //新开店模板数据从品类接口获取
        if (SalesPlanTypeEnum.PLAN_FIFTEEN.getType().equals(type)) {
            List<StorePackageSkuDTO> skuDtoList = categoryFacade.queryStorePackageSku();
            if (CollectionUtils.isEmpty(skuDtoList)) {
                return Collections.emptyList();
            }
            List<SalesWriteDTO> writeDtoList = new ArrayList<>();
            for (StorePackageSkuDTO skuDto : skuDtoList) {
                SalesWriteDTO writeDto = new SalesWriteDTO();
                writeDto.setChannelCode(skuDto.getChannelCode());
                writeDto.setChannelName(skuDto.getChannelName());
                writeDto.setProvinceName(skuDto.getProvinceName());
                writeDto.setCityName(skuDto.getCityName());
                writeDto.setSkuCode(skuDto.getSkuCode());
                writeDto.setSkuName(skuDto.getSkuName());
                writeDto.setUnit(skuDto.getSaleUnitName());
                writeDto.setWeekOneNum(skuDto.getSkuQty().intValue());
                writeDto.setWeekTwoNum(skuDto.getSkuQty().intValue());
                writeDto.setWeekThreeNum(skuDto.getSkuQty().intValue());
                writeDto.setWeekFourNum(skuDto.getSkuQty().intValue());
                writeDto.setWeekFiveNum(skuDto.getSkuQty().intValue());
                writeDto.setWeekSixNum(skuDto.getSkuQty().intValue());
                writeDtoList.add(writeDto);
            }
            return writeDtoList;
        } else if (SalesPlanTypeEnum.PLAN_SIXTEEN.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_SEVEN.getType());
            types.add(SalesOtherTypeEnum.PLAN_EIGHT.getType());
            types.add(SalesOtherTypeEnum.PLAN_NINE.getType());
            types.add(SalesOtherTypeEnum.PLAN_TEN.getType());
            types.add(SalesOtherTypeEnum.PLAN_FIFTEEN.getType());
        } else if (SalesPlanTypeEnum.PLAN_ELEVEN.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_ELEVEN.getType());
        } else if (SalesPlanTypeEnum.PLAN_TWELVE.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_TWELVE.getType());
        } else if (SalesPlanTypeEnum.PLAN_THIRTEEN.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_THIRTEEN.getType());
        } else if (SalesPlanTypeEnum.PLAN_FOURTEEN.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_FOURTEEN.getType());
        } else if (SalesPlanTypeEnum.PLAN_SEVENTEEN.getType().equals(type)) {
            types.add(SalesOtherTypeEnum.PLAN_SIXTEEN.getType());
        }
        SalesPlanOtherDTO otherDto = new SalesPlanOtherDTO();
        otherDto.setPlanStartDate(startTimeOne);
        otherDto.setPlanImportDate(startTimeTwo);
        otherDto.setPlanEndDate(startTimeSix);
        otherDto.setTypeList(types);
        //获取
        List<SalesPlanOtherDTO> dtoList = salesPlanOtherRespository.getLastPlanData(otherDto);
        if (dtoList.size() == 0) {
            return Collections.emptyList();
        }
        //获取所有不重复的商品编码
        List<String> skus = dtoList.stream().map(SalesPlanOtherDTO::getSkuCode).distinct().collect(Collectors.toList());
        //获取单位转换比例信息
        List<SkuUnitDTO> unitList = itemCoreFacade.getConversionRatio(skus, SkuUnitTypeEnum.SALES_UNIT.getUnitType());
        //转换为销售单位
        this.calculationPro(dtoList, unitList);
        //根据类型、省份、城市、门店（没有为""）、商品分组
        Map<String, List<SalesPlanOtherDTO>> dateMap = dtoList.stream().collect(Collectors.groupingBy
                (item -> item.getType() + item.getProvinceCode()
                        + (ObjectUtil.isNotNull(item.getCityCode()) ? item.getCityCode() : "")
                        + (ObjectUtil.isNotNull(item.getCountyCode()) ? item.getCountyCode() : "")
                        + (ObjectUtil.isNotNull(item.getStoreCode()) ? item.getStoreCode() : "") + item.getSkuCode()));
        List<SalesWriteDTO> writeList = new ArrayList<>();
        dateMap.forEach((k, v) -> {
            SalesWriteDTO writeDto = new SalesWriteDTO();
            writeDto.setPlanNo(v.get(0).getSalesPlanOtherNo());
            writeDto.setChannelCode(v.get(0).getChannelCode());
            writeDto.setChannelName(v.get(0).getChannelName());
            writeDto.setProvinceName(v.get(0).getProvinceName());
            writeDto.setCityName(v.get(0).getCityName());
            writeDto.setStoreCode(v.get(0).getStoreCode());
            writeDto.setSkuCode(v.get(0).getSkuCode());
            writeDto.setSkuName(v.get(0).getSkuName());
            //需要转换
            List<SkuUnitDTO> skuUnits = unitList.stream().filter(unit -> unit.getSkuCode().equals(v.get(0).getSkuCode())).collect(Collectors.toList());
            if (skuUnits.size() > 0) {
                writeDto.setUnit(skuUnits.get(0).getUnitName());
            }
            v.forEach(dto -> {
                Date startDate = DateUtil.parseDateTime(DateUtil.formatDateTime(dto.getPlanStartDate()));
                if (startTimeTwo.compareTo(startDate) == 0) {
                    writeDto.setWeekOneNum(dto.getPlanQty().intValue());
                } else if (startTimeThree.compareTo(startDate) == 0) {
                    writeDto.setWeekTwoNum(dto.getPlanQty().intValue());
                } else if (startTimeFour.compareTo(startDate) == 0) {
                    writeDto.setWeekThreeNum(dto.getPlanQty().intValue());
                } else if (startTimeFive.compareTo(startDate) == 0) {
                    writeDto.setWeekFourNum(dto.getPlanQty().intValue());
                } else if (startTimeSix.compareTo(startDate) == 0) {
                    writeDto.setWeekFiveNum(dto.getPlanQty().intValue());
                }
            });
            writeList.add(writeDto);
        });
        return writeList;
    }

    */
/**
     * 修改上次计划量，上次确认量
     *//*

    public void updateLastDate(List<SalesPlanOtherDTO> salesLists, Integer type) {
        //获取前一周到后五周的日期
        List<Map<String, Date>> lastDateMap = MyDateUtil.getWeekDatess(new Date(), CommonConstants.SIX);
        //List<Map<String, Date>> lastDateMap = MyDateUtil.getWeekDatess(salesLists.get(0).getPlanImportDate(), CommonConstants.SIX);
        //上一次计划第一周时间
        Date startTimeOne = lastDateMap.get(0).get("startTime");
        //上一次计划第二周时间（对应当前周）
        Date startTimeTwo = lastDateMap.get(1).get("startTime");
        //上一次计划第三周时间
        Date startTimeThree = lastDateMap.get(2).get("startTime");
        //上一次计划第四周时间
        Date startTimeFour = lastDateMap.get(3).get("startTime");
        //上一次计划第五周时间
        Date startTimeFive = lastDateMap.get(4).get("startTime");
        //上一次计划第六周时间
        Date startTimeSix = lastDateMap.get(5).get("startTime");
        SalesPlanOtherDTO dto = new SalesPlanOtherDTO();
        List<String> plans = new ArrayList<>();
        dto.setPlanStartDate(startTimeOne);
        dto.setPlanImportDate(startTimeTwo);
        dto.setPlanEndDate(startTimeSix);
        String plana;
        String planb;
        String planc;
        String pland;
        String plane;
        //销售计划
        if (type == 1) {
            plana = SalesOtherTypeEnum.PLAN_ELEVEN.getType();
            planb = SalesOtherTypeEnum.PLAN_TWELVE.getType();
            planc = SalesOtherTypeEnum.PLAN_THIRTEEN.getType();
            pland = SalesOtherTypeEnum.PLAN_FOURTEEN.getType();
            plane = SalesOtherTypeEnum.PLAN_SIXTEEN.getType();
            plans.add(plana);
            plans.add(planb);
            plans.add(planc);
            plans.add(pland);
            plans.add(plane);
        }
        //新开店
        else if (type == 2) {
            plana = SalesOtherTypeEnum.PLAN_FIVE.getType();
            planb = SalesOtherTypeEnum.PLAN_SIX.getType();
            plans.add(plana);
            plans.add(planb);
        }
        //新品
        else if (type == 3) {
            plana = SalesOtherTypeEnum.PLAN_SEVEN.getType();
            planb = SalesOtherTypeEnum.PLAN_EIGHT.getType();
            planc = SalesOtherTypeEnum.PLAN_NINE.getType();
            pland = SalesOtherTypeEnum.PLAN_TEN.getType();
            plane = SalesOtherTypeEnum.PLAN_FIFTEEN.getType();
            plans.add(plana);
            plans.add(planb);
            plans.add(planc);
            plans.add(pland);
            plans.add(plane);
        } else {
            //营销
            plana = SalesOtherTypeEnum.PLAN_ONE.getType();
            planb = SalesOtherTypeEnum.PLAN_TWO.getType();
            planc = SalesOtherTypeEnum.PLAN_THREE.getType();
            pland = SalesOtherTypeEnum.PLAN_FOUR.getType();
            plans.add(plana);
            plans.add(planb);
            plans.add(planc);
            plans.add(pland);
        }
        dto.setTypeList(plans);
        //获取当前周第二周到第六周的数据
        List<SalesPlanOtherDTO> salesList = salesPlanOtherRespository.getLastPlanData(dto);
        salesList = salesList.stream().filter(item -> DateUtil.parseDateTime(DateUtil.formatDateTime(item.getPlanStartDate())).compareTo(startTimeTwo) != 0).collect(Collectors.toList());
        if (salesList.size() == 0) {
            return;
        }
        List<SalesPlanOtherDTO> dtoList = new ArrayList<>();
        if (type == 1) {
            //销售计划
            salesList.forEach(item -> {
                //筛选（计划类型、省份、城市、门店、商品、计划开始时间）
                List<SalesPlanOtherDTO> dtos = salesLists.stream().filter(dtoa ->
                        item.getChannelCode().equals(dtoa.getChannelCode()) &&
                                item.getType().equals(dtoa.getType()) &&
                                item.getProvinceCode().equals(dtoa.getProvinceCode()) &&
                                (ObjectUtil.isNull(item.getCityCode()) ? true : (ObjectUtil.isNull(dtoa.getCityCode()) ? false : item.getCityCode().equals(dtoa.getCityCode()))) &&
                                (ObjectUtil.isNull(item.getStoreCode()) ? true : (ObjectUtil.isNull(dtoa.getStoreCode()) ? false : item.getStoreCode().equals(dtoa.getStoreCode()))) &&
                                item.getSkuCode().equals(dtoa.getSkuCode()) &&
                                item.getPlanStartDate().compareTo(dtoa.getPlanStartDate()) == 0)
                        .collect(Collectors.toList());
                //说明同一个省份下有多条记录
                if (dtos.size() > 1) {
                    //如果只有省
                    if (ObjectUtil.isNull(item.getCityCode()) && ObjectUtil.isNull(item.getStoreCode())) {
                        //过滤去掉城市和门店为空的省份数据
                        dtos = dtos.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                && ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                    //如果有省和城市
                    else if (ObjectUtil.isNotNull(item.getCityCode()) && ObjectUtil.isNull(item.getStoreCode())) {
                        //过滤去掉门店为空的数据
                        dtos = dtos.stream().filter(repeat -> ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                }
                if (dtos.size() == 1) {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastPlanQty(item.getPlanQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelConfirmedQty(BigDecimal.ZERO);
                    item.setAllchannelConfirmedQty(BigDecimal.ZERO);
                    item.setStatus(SalesConfirmStatusEnum.UNCONFIRMED.getType());
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                } else {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastPlanQty(item.getPlanQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setPlanQty(BigDecimal.ZERO);
                    item.setConfirmedQty(BigDecimal.ZERO);
                    item.setChannelConfirmedQty(BigDecimal.ZERO);
                    item.setAllchannelConfirmedQty(BigDecimal.ZERO);
                    item.setStatus(SalesConfirmStatusEnum.UNCONFIRMED.getType());
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                }
            });
        } else if (type == 2){
            //新开店
            salesList.forEach(item -> {
                //筛选（计划类型、省份、城市、门店、商品、计划开始时间）
                List<SalesPlanOtherDTO> dtos = salesLists.stream().filter(sale ->
                        sale.getType().equals(item.getType()) &&
                                sale.getSkuCode().equals(item.getSkuCode()) &&
                                sale.getPlanStartDate().compareTo(item.getPlanStartDate()) == 0 &&
                                sale.getProvinceCode().equals(item.getProvinceCode()) &&
                                (ObjectUtil.isNull(item.getCityCode()) ? true : (ObjectUtil.isNull(sale.getCityCode()) ? false : item.getCityCode().equals(sale.getCityCode())))).collect(Collectors.toList());
                //说明同一个省份下有多条记录
                if (dtos.size() > 1) {
                    //如果只有省
                    if (ObjectUtil.isNull(item.getCityCode())) {
                        //过滤去掉城市和门店为空的省份数据
                        dtos = dtos.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                ).collect(Collectors.toList());
                    }
                }
                if (dtos.size() == 1) {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                } else {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setConfirmedQty(BigDecimal.ZERO);
                    item.setChannelConfirmedQty(BigDecimal.ZERO);
                    item.setAllchannelConfirmedQty(BigDecimal.ZERO);
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                }
            });
        } else {
            //新品加营销
            salesList.forEach(item -> {
                //筛选（计划类型、省份、城市、门店、商品、计划开始时间）
                List<SalesPlanOtherDTO> dtos = salesLists.stream().filter(sale ->
                        sale.getType().equals(item.getType()) &&
                                sale.getSkuCode().equals(item.getSkuCode()) &&
                                sale.getPlanStartDate().compareTo(item.getPlanStartDate()) == 0 &&
                                sale.getProvinceCode().equals(item.getProvinceCode()) &&
                                (ObjectUtil.isNull(item.getCityCode()) ? true : (ObjectUtil.isNull(sale.getCityCode()) ? false : item.getCityCode().equals(sale.getCityCode()))) &&
                                (ObjectUtil.isNull(item.getStoreCode()) ? true : (ObjectUtil.isNull(sale.getStoreCode()) ? false : item.getStoreCode().equals(sale.getStoreCode())))).collect(Collectors.toList());
                //说明同一个省份下有多条记录
                if (dtos.size() > 1) {
                    //如果只有省
                    if (ObjectUtil.isNull(item.getCityCode()) && ObjectUtil.isNull(item.getStoreCode())) {
                        //过滤去掉城市和门店为空的省份数据
                        dtos = dtos.stream().filter(repeat -> ObjectUtil.isNull(repeat.getCityCode())
                                && ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                    //如果有省和城市
                    else if (ObjectUtil.isNotNull(item.getCityCode()) && ObjectUtil.isNull(item.getStoreCode())) {
                        //过滤去掉门店为空的数据
                        dtos = dtos.stream().filter(repeat -> ObjectUtil.isNull(repeat.getStoreCode())).collect(Collectors.toList());
                    }
                }
                if (dtos.size() == 1) {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                } else {
                    item.setId(item.getId());
                    item.setSalesPlanOtherNo(item.getSalesPlanOtherNo());
                    item.setLastConfirmedQty(item.getConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setChannelLastConfirmedQty(item.getChannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setAllchannelLastConfirmedQty(item.getAllchannelConfirmedQty().setScale(0, BigDecimal.ROUND_HALF_UP));
                    item.setConfirmedQty(BigDecimal.ZERO);
                    item.setChannelConfirmedQty(BigDecimal.ZERO);
                    item.setAllchannelConfirmedQty(BigDecimal.ZERO);
                    item.setPlanImportDate(new Date());
                    dtoList.add(item);
                }
            });
        }
        //异步修改数据到ES
        startUpdate(dtoList);
        salesPlanOtherRespository.updateLastDate(dtoList);
    }

    */
/**
     * 获取当前日期对应的标题
     *
     * @return
     *//*

    private List<String> getTitleByDate(String type) {
        List<String> result = new ArrayList<>();
        List<Map<String, String>> dateMap = MyDateUtil.getWeekDateBySize(new Date(), CommonConstants.SIX);
        //获取当前时间是多少周
        int dateIndex = DateUtil.weekOfYear(new Date());
        int i = 0;
        for (Map<String, String> map : dateMap) {
            String startDate = map.get("startTime");
            String endDate = map.get("endTime");
            if (i == 0) {
                result.add("当前周（销售数量）\n（默认为上一周导入的第二周计划数量，不用填，更改无效）\n" + startDate + "-" + endDate);
            }
            if (SalesPlanTypeEnum.PLAN_FIFTEEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SIXTEEN.getType().equals(type)) {
                if (i == 1) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
                if (i == 2) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
                if (i == 3) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
                if (i == 4) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
            } else {
                if (i == 1) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
                if (i == 2) {
                    result.add("W" + (dateIndex + i) + "（销售数量）（必填）\n" + startDate + "-" + endDate);
                }
                if (i == 3) {
                    result.add("W" + (dateIndex + i) + "（销售数量）\n" + startDate + "-" + endDate);
                }
                if (i == 4) {
                    result.add("W" + (dateIndex + i) + "（销售数量）\n" + startDate + "-" + endDate);
                }
            }
            if (i == 5) {
                result.add("W" + (dateIndex + i) + "（销售数量）\n" + startDate + "-" + endDate);
            }
            i++;
        }
        return result;
    }

    private List<List<Object>> getExcelData(List<SalesWriteDTO> salesList, String type) {
        List<List<Object>> excelList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(salesList)) {
            for (SalesWriteDTO salesWriteDTO : salesList) {
                List<Object> item = new ArrayList<>();
                item.add(salesWriteDTO.getChannelCode());
                item.add(salesWriteDTO.getChannelName());
                item.add(salesWriteDTO.getProvinceName());
                item.add(ObjectUtil.isNotNull(salesWriteDTO.getCityName()) ? salesWriteDTO.getCityName() : "");
                if (SalesPlanTypeEnum.PLAN_ELEVEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SIXTEEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SEVENTEEN.getType().equals(type)) {
                    item.add(ObjectUtil.isNotNull(salesWriteDTO.getStoreCode()) ? salesWriteDTO.getStoreCode() : "");
                }
                item.add(salesWriteDTO.getSkuCode());
                item.add(salesWriteDTO.getSkuName());
                item.add(salesWriteDTO.getUnit());
                if (SalesPlanTypeEnum.PLAN_FIFTEEN.getType().equals(type)) {
                    item.add(salesWriteDTO.getWeekOneNum());
                    item.add(salesWriteDTO.getWeekTwoNum());
                    item.add(salesWriteDTO.getWeekThreeNum());
                    item.add(salesWriteDTO.getWeekFourNum());
                    item.add(salesWriteDTO.getWeekFiveNum());
                    item.add(salesWriteDTO.getWeekSixNum());
                } else {
                    item.add(salesWriteDTO.getWeekOneNum());
                    item.add("");
                    item.add("");
                    item.add("");
                    item.add("");
                    item.add("");
                }

                excelList.add(item);
            }
        } else {
            //第一次导出导入模板没有数据（画一行）
            List<Object> item = new ArrayList<>();
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            if (SalesPlanTypeEnum.PLAN_ELEVEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SIXTEEN.getType().equals(type) || SalesPlanTypeEnum.PLAN_SEVENTEEN.getType().equals(type)) {
                item.add("");
            }
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            item.add("");
            excelList.add(item);
        }
        return excelList;
    }

    private List<SalesPlanOtherInfoDTO> groupTarget(List<Map<String, String>> listPageInfo, Integer level) {
        if (listPageInfo.size() == CommonConstants.ZERO) {
            return Collections.emptyList();
        }
        List<SalesPlanOtherInfoDTO> salesPlanOtherInfoList = new ArrayList<>();
        for (Map<String, String> map : listPageInfo) {
            SalesPlanOtherInfoDTO salesPlanOtherInfo = new SalesPlanOtherInfoDTO();
            //上次计划量
            List<BigDecimal> lastPlanQtys = new ArrayList<>();
            //上次确认量
            List<BigDecimal> lastConfirmedQtys = new ArrayList<>();
            //计划量
            List<BigDecimal> planQtys = new ArrayList<>();
            //确认量
            List<BigDecimal> confirmedQtys = new ArrayList<>();
            //计划差异
            List<BigDecimal> planDifferences = new ArrayList<>();
            //计划比例
            List<BigDecimal> planProportions = new ArrayList<>();
            //渠道确认量
            List<BigDecimal> channelConfirmedQtys = new ArrayList<>();
            //全渠道确认量
            List<BigDecimal> allchannelConfirmedQtys = new ArrayList<>();
            //渠道上次确认量
            List<BigDecimal> channelLastConfirmedQtys = new ArrayList<>();
            //全渠道上次确认量
            List<BigDecimal> allchannelLastConfirmedQtys = new ArrayList<>();
            List<Integer> statusList = new ArrayList<>();
            List<String> typeList = new ArrayList<>();
            List<Long> idsList = new ArrayList<>();
            for (String key : map.keySet()) {
                //判断key是否匹配正则
                String regex = "^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)).*$";
                if (ReUtil.isMatch(regex, key)) {
                    NumberFormat percent = NumberFormat.getPercentInstance();
                    percent.setMaximumFractionDigits(3);
                    String value = (String) map.get(key);
                    //分割指标字符串
                    String[] target = value.split(":");
                    //上次计划量
                    BigDecimal lastPlanQty = new BigDecimal(target[0]);
                    //上次确认量
                    BigDecimal lastConfirmedQty = new BigDecimal(target[1]);
                    //计划量
                    BigDecimal planQty = new BigDecimal(target[2]);
                    //确认量
                    BigDecimal confirmedQty = new BigDecimal(target[3]);
                    //计划与确认差值
                    BigDecimal planDifference;
                    //计划与确认比例
                    BigDecimal planProportion;
                    //渠道确认量
                    BigDecimal channelConfirmedQty = new BigDecimal(target[4]);
                    //全渠道确认量
                    BigDecimal allchannelConfirmedQty = new BigDecimal(target[5]);
                    //渠道上次确认量
                    BigDecimal channelLastConfirmedQty = new BigDecimal(target[6]);
                    //全渠道上次确认量
                    BigDecimal allchannelLastConfirmedQty = new BigDecimal(target[7]);
                    //确认状态
                    Integer status = Integer.valueOf(target[8]);
                    //计划类型
                    String type = target[9];
                    Long id = Long.valueOf(target[10]);
                    statusList.add(status);
                    typeList.add(type);
                    idsList.add(id);
                    if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                        //计划与确认差值(渠道)(确认量-计划量)
                        planDifference = allchannelConfirmedQty.subtract(planQty);
                        //计划与确认比例(渠道)((确认量-计划量)/确认量)
                        planProportion = allchannelConfirmedQty.compareTo(BigDecimal.ZERO) == 0 || allchannelConfirmedQty.subtract(planQty).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : ((allchannelConfirmedQty.subtract(planQty)).divide(allchannelConfirmedQty, 7, BigDecimal.ROUND_HALF_UP));
                    } else {
                        //计划与确认差值(渠道)(确认量-计划量)
                        planDifference = channelConfirmedQty.subtract(planQty);
                        //计划与确认比例(渠道)((确认量-计划量)/确认量)
                        planProportion = channelConfirmedQty.compareTo(BigDecimal.ZERO) == 0 || channelConfirmedQty.subtract(planQty).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : ((channelConfirmedQty.subtract(planQty)).divide(channelConfirmedQty, 7, BigDecimal.ROUND_HALF_UP));
                        //计划与确认差值(渠道)(确认量-计划量)
                        planDifference = confirmedQty.subtract(planQty);
                        //计划与确认比例(渠道)((确认量-计划量)/确认量)
                        planProportion = confirmedQty.compareTo(BigDecimal.ZERO) == 0 || confirmedQty.subtract(planQty).compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO : ((confirmedQty.subtract(planQty)).divide(confirmedQty, 7, BigDecimal.ROUND_HALF_UP));
                    }
                    //放入对应指标集合
                    lastPlanQtys.add(lastPlanQty);
                    lastConfirmedQtys.add(lastConfirmedQty);
                    planQtys.add(planQty);
                    confirmedQtys.add(confirmedQty);
                    planDifferences.add(planDifference);
                    planProportions.add(planProportion);
                    channelConfirmedQtys.add(channelConfirmedQty);
                    allchannelConfirmedQtys.add(allchannelConfirmedQty);
                    channelLastConfirmedQtys.add(channelLastConfirmedQty);
                    allchannelLastConfirmedQtys.add(allchannelLastConfirmedQty);
                }
            }
            //salesPlanOtherInfo.setIds(idsList);
            //确认量
            List<BigDecimal> confirms;
            //上次确认量
            List<BigDecimal> lastConfirms;
            //下级确认量
            List<BigDecimal> subordinateConfirms;
            salesPlanOtherInfo.setTypeList(typeList);
            salesPlanOtherInfo.setStatusList(statusList);
            //全渠道负责人
            if (level.equals(CommonConstants.OTHER_PLAN_LEVEL_TWO)) {
                confirms = allchannelConfirmedQtys;
                lastConfirms = allchannelLastConfirmedQtys;
                salesPlanOtherInfo.setSubordinateConfirmedQtyLabel(SalesPlanOtherEnum.SUBORDINATE_CONFIRMED_QTY.getDesc());
                salesPlanOtherInfo.setSubordinateConfirmedQtys(channelConfirmedQtys);
            }
            //渠道负责人、渠道负责人下级
            else {
                confirms = confirmedQtys;
                lastConfirms = lastConfirmedQtys;
            }
            salesPlanOtherInfo.setLastPlanQtyLabel(SalesPlanOtherEnum.LAST_PLAN_QTY.getDesc());
            salesPlanOtherInfo.setLastPlanQtys(lastPlanQtys);

            salesPlanOtherInfo.setLastConfirmedQtyLabel(SalesPlanOtherEnum.LAST_CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setLastConfirmedQtys(lastConfirms);

            salesPlanOtherInfo.setConfirmedQtyLabel(SalesPlanOtherEnum.CONFIRMED_QTY.getDesc());
            salesPlanOtherInfo.setConfirmedQtys(confirms);
            salesPlanOtherInfo.setPlanQtyLabel(SalesPlanOtherEnum.PLAN_QTY.getDesc());
            salesPlanOtherInfo.setPlanQtys(planQtys);
            salesPlanOtherInfo.setPlanDifferenceLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_DIFFERIN.getDesc());
            salesPlanOtherInfo.setPlanDifferences(planDifferences);
            salesPlanOtherInfo.setPlanProportionLabel(SalesPlanOtherEnum.PLAN_CONFIRMED_PROPORTION.getDesc());
            salesPlanOtherInfo.setPlanProportions(planProportions);
            //获取区域名称
            String channel = "";
            salesPlanOtherInfo.setArea((!ObjectUtils.isEmpty(map.get("province_name")) ? map.get("province_name") : "")
                    + (!ObjectUtils.isEmpty(map.get("city_name")) ? "/" + map.get("city_name") : "") + (!ObjectUtils.isEmpty(map.get("county_name")) ? "/" + map.get("county_name") : "")
            );
            //获取门店
            salesPlanOtherInfo.setStore(!ObjectUtils.isEmpty(map.get("store_name")) ? map.get("store_code") + "/" + map.get("store_name") : null);
            //获取渠道名称
            salesPlanOtherInfo.setChannel(!ObjectUtils.isEmpty(map.get("channel_name")) ? map.get("channel_name") : "");
            //取商品信息
            salesPlanOtherInfo.setSkuCode(!ObjectUtils.isEmpty(map.get("sku_code")) ? map.get("sku_code") : "");
            salesPlanOtherInfo.setSkuName(!ObjectUtils.isEmpty(map.get("sku_name")) ? map.get("sku_code") + "/" + map.get("sku_name") : "");
            //获取品类
            salesPlanOtherInfo.setCategory((!ObjectUtils.isEmpty(map.get("pri_category_name")) ? map.get("pri_category_name") : "") +
                    (!ObjectUtils.isEmpty(map.get("sec_category_name")) ? "/" + map.get("sec_category_name") : "") + (!ObjectUtils.isEmpty(map.get("ter_category_name")) ? "/" + map.get("ter_category_name") : ""));
            salesPlanOtherInfo.setType(SalesOtherTypeEnum.getNameByType(map.get("type")));
            salesPlanOtherInfoList.add(salesPlanOtherInfo);
        }
        return salesPlanOtherInfoList;
    }

    private List<List<Object>> getExcelList(List<SalesPlanOtherInfoDTO> salesPlan, List<String> targets, List<String> dateTitles) {
        List<SalesPlanOtherInfoDTO> salesPlanOtherInfoList = new ArrayList<>();
        List<List<Object>> exportDataList = new ArrayList<>();
        //将分组后的数据汇总
        salesPlan.forEach(key -> {
            for (int i = 0; i < targets.size(); i++) {
                List<Object> itemRow = new ArrayList<>();
                //加入渠道，区域，门店，品类，商品  信息
                itemRow.add(key.getChannel());
                itemRow.add(key.getType());
                itemRow.add(key.getArea());
                itemRow.add(ObjectUtil.isNotNull(key.getStore()) ? key.getStore() : "");
                itemRow.add(key.getCategory());
                itemRow.add(key.getSkuName());
                //加入指标
                itemRow.add(targets.get(i));
                //导入人没有下级确认量
                if (targets.size() == 6) {
                    //加入数据()
                    for (int j = 0; j < (dateTitles.size() - 1); j++) {
                        //获取指标集合，这里没有排序，默认使用枚举的顺序
                        switch (i) {
                            case 0:
                                itemRow.add(key.getLastPlanQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getLastPlanQtys().get(j));
                                break;
                            case 1:
                                itemRow.add(key.getLastConfirmedQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getLastConfirmedQtys().get(j));
                                break;
                            case 2:
                                itemRow.add(key.getPlanQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getPlanQtys().get(j));
                                break;
                            case 3:
                                itemRow.add(key.getConfirmedQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getConfirmedQtys().get(j));
                                break;
                            case 4:
                                itemRow.add(key.getPlanDifferences().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getPlanDifferences().get(j));
                                break;
                            case 5:
                                itemRow.add(key.getPlanProportions().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : (key.getPlanProportions().get(j).multiply(new BigDecimal(100)).setScale(3, BigDecimal.ROUND_HALF_UP)) + "%");
                                break;
                            default:
                                break;
                        }
                    }
                } else {
                    //加入数据
                    for (int j = 0; j < (dateTitles.size() - 1); j++) {
                        //获取指标集合，这里没有排序，默认使用枚举的顺序
                        switch (i) {
                            case 0:
                                itemRow.add(key.getLastPlanQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getLastPlanQtys().get(j));
                                break;
                            case 1:
                                itemRow.add(key.getLastConfirmedQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getLastConfirmedQtys().get(j));
                                break;
                            case 2:
                                itemRow.add(key.getPlanQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getPlanQtys().get(j));
                                break;
                            case 3:
                                itemRow.add(key.getSubordinateConfirmedQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getSubordinateConfirmedQtys().get(j));
                                break;
                            case 4:
                                itemRow.add(key.getConfirmedQtys().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getConfirmedQtys().get(j));
                                break;
                            case 5:
                                itemRow.add(key.getPlanDifferences().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : key.getPlanDifferences().get(j));
                                break;
                            case 6:
                                itemRow.add(key.getPlanProportions().get(j).compareTo(BigDecimal.ZERO) == 0 ? "-" : (key.getPlanProportions().get(j).multiply(new BigDecimal(100)).setScale(3, BigDecimal.ROUND_HALF_UP)) + "%");
                                break;
                            default:
                                break;
                        }
                    }
                }
                //合计
                BigDecimal total = BigDecimal.ZERO;
                String percentage = "";
                //获取除日期外的下标
                int index = itemRow.size() - (dateTitles.size() - 1);
                List<Object> numRow = new ArrayList<>();
                numRow.addAll(itemRow);
                for (int a = 0; a < index; a++) {
                    numRow.remove(numRow.get(0));
                }
                //循环增加查询的日期对应指标数量
                for (Object obj : numRow) {
                    BigDecimal num = BigDecimal.ZERO;
                    if ("-".equals(obj)) {
                        num = BigDecimal.ZERO;
                        total = total.add(num);
                    } else {
                        if (obj.toString().contains("%")) {
                            String nums = obj.toString().substring(0, obj.toString().length() - 1);
                            num = new BigDecimal(nums);
                            total = total.add(num);
                            percentage = total + "%";
                        } else {
                            num = new BigDecimal(obj.toString());
                            total = total.add(num);
                        }
                    }
                }
                if ("".equals(percentage)) {
                    itemRow.add(total.equals(BigDecimal.ZERO) ? "-" : total);
                } else {
                    itemRow.add(percentage);
                }
                exportDataList.add(itemRow);
            }
        });
        return exportDataList;
    }

    */
/*public void startInsert(List<SalesPlanOtherDTO> dtoList) {
        //异步新增数据到ES
        new Thread((new Runnable() {
            @Override
            public void run() {
                try {
                    log.info("-------异步新增数据到ES------");
                    salesPlanOtherEsService.asyncInsertOtherEsData(dtoList);
                } catch (Exception ex) {
                    log.info("异步新增数据到ES失败，" + ex);
                }
            }
        })).start();
    }

    public void startUpdate(List<SalesPlanOtherDTO> dtoList) {
        //异步修改数据到ES
        new Thread((new Runnable() {
            @Override
            public void run() {
                try {
                    log.info("-------异步修改数据到ES------");
                    salesPlanOtherEsService.asyncUpdateOtherEsData(dtoList);
                } catch (Exception ex) {
                    log.info("异步修改数据到ES，" + ex);
                }
            }
        })).start();
    }

    public void startUpdateAll() {
        //异步修改ES的计划确认状态
        new Thread((new Runnable() {
            @Override
            public void run() {
                try {
                    log.info("-------异步修改ES的计划确认状态------");
                    salesPlanOtherEsService.asyncUpdateOtherEsStatus();
                } catch (Exception ex) {
                    log.info("异步修改ES的计划确认状态，" + ex);
                }
            }
        })).start();
    }*//*


}*/
